package com.xmy.study.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xmy.study.entity.ChaPlan;
import com.xmy.study.entity.StoreData;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.web.bind.annotation.RequestParam;
import scala.Int;

import java.util.List;

@Mapper
public interface ChaPlanMapper extends BaseMapper<ChaPlan> {

    @Select("SELECT c.* " +
            "FROM cha_plan c " +
            "INNER JOIN ( " +
            "    SELECT student_id, MAX(school_date) as max_school_date " +
            "    FROM cha_plan " +
            "    GROUP BY student_id " +
            ") as latest_cha_plan ON c.student_id = latest_cha_plan.student_id AND c.school_date = latest_cha_plan.max_school_date " +
            "${ew.customSqlSegment}")
    List<ChaPlan> getClearanceRateChaPlan(@Param(Constants.WRAPPER) Wrapper wrapper);


    @Select({"<script>",
            "SELECT",
                    "school_id,",
                    "year_part,",
                    "quarter_num,",
                    "subjects_id,",
                    "task_category_id,",
                    "course_version_id,",
                    "grade_id,",
                    "teacher_id,",
                    "class_type_id,",
                    "year_class_id,",
                    "student_id,",
                    "lesson_num,",
                    "lowest_shutnum,",
                    "student_name,",
                    "pass_rade,",
                    "( right_num / lowest_shutnum )* 100 AS already_pass_rade,",
                    "IF",
                    "(( right_num + amend_num ) &gt;= lowest_shutnum, 0, right_num ) AS right_num,",
                    "IF",
                    "(( right_num + amend_num ) &gt;= lowest_shutnum, 0, amend_num ) AS amend_num,",
                    "( CASE WHEN brush_count = 0 THEN 1 WHEN brush_count > 0 AND ( right_num + amend_num ) &gt;= lowest_shutnum THEN brush_count + 1 ELSE brush_count END ) AS brush_count ",
                    "FROM",
                    "(",
                    "SELECT",
                      "year_part,",
                      "quarter_num,",
                      "subjects_id,",
                      "task_category_id,",
                      "course_version_id,",
                      "not_brush,",
                      "task_course_num,",
                      "school_id,",
                      "grade_id,",
                      "teacher_id,",
                      "class_type_id,",
                      "year_class_id,",
                      "student_id,",
                      "student_name,",
                      "lesson_num,",
                      "IFNULL( lowest_shutnum, 0 ) AS lowest_shutnum,",
                      "IFNULL( right_num, 0 ) AS right_num,",
                      "IFNULL( amend_num, 0 ) AS amend_num,",
                      "IFNULL( pass_rade, task_pass_rade ) AS pass_rade,",
                      "IFNULL( brush_count, 0 ) AS brush_count ",
                    "FROM",
                      "(",
                      "SELECT",
                        "t1.year_part,",
                        "t1.quarter_num,",
                        "t1.subjects_id,",
                        "t1.task_category_id,",
                        "t1.course_version_id,",
                        "t1.not_brush,",
                        "t1.pass_rade AS task_pass_rade,",
                        "t2.school_id,",
                        "t2.grade_id,",
                        "t4.teacher_id,",
                        "t2.class_type_id_new AS class_type_id,",
                        "t4.year_class_id,",
                        "t2.student_id,",
                        "t5.`name` AS student_name,",
                        "(CASE WHEN t3.right_num is not null AND t3.pass_rade &gt;0 and (right_num + amend_num ) &gt;= t3.lowest_shutnum AND ( t3.right_num / t3.lowest_shutnum )* 100 &gt;= t3.pass_rade THEN t3.lowest_shutnum ELSE t1.lowest_shutnum END) as lowest_shutnum,",
                        "t1.task_course_num AS lesson_num,",
                        "t1.task_course_num,",
                        "t3.right_num,",
                        "t3.amend_num,",
                        "t3.pass_rade,",
                        "t3.brush_count ",
                      "FROM",
                        "edu_task AS t1",
                        "INNER JOIN xmy_erp_db.student_grade AS t2 ON t1.year_part = t2.year_part ",
                        "AND t1.quarter_num = t2.quarter_num ",
                        "AND t1.deleted = t2.deleted ",
                        "AND t1.year_class_id = t2.year_class_id ",
                        "AND t1.class_type_id = t2.class_type_id_new ",
                        "AND t1.course_version_id = 1676874588501311488",
                        "and t1.subjects_id = ${subjectsId}",
                        "INNER JOIN xmy_erp_db.grade AS t4 ON t2.grade_id = t4.id",
                        "INNER JOIN xmy_erp_db.student AS t5 ON t2.student_id = t5.id",
                        "LEFT JOIN cha_plan AS t3 ON t1.year_part = t3.year_part ",
                        "AND t1.quarter_num = t3.quarter_num ",
                        "AND t2.student_id = t3.student_id ",
                        "AND t1.class_type_id = t3.class_type_id ",
                        "AND t1.task_category_id = t3.task_category_id ",
                        "AND t1.task_course_num = t3.lesson_num ",
                        "AND t3.is_last = 1 ",
                        "and t3.deleted = 0",
                      "WHERE",
                        "t1.year_part = ${yearPart}",
                        "AND t1.quarter_num = ${quarterNum} ",
                        "AND t1.task_category_id = ${taskCategoryId} ",
                        "AND t1.deleted = 0 ",
                        "<when test='isHistory==0'>",
                            "and t1.task_course_num = ${lessonNum}",
                        "</when>",
                        "<when test='isHistory==1'>",
                            "and t1.task_course_num &lt;= ${lessonNum}",
                        "</when>",
                        "AND t2.subjects_id = ${subjectsId} ",
                        "AND t2.lesson_type = 1 ",
                        "AND t2.reading_status IN ( 1, 5 ) ",
                        "AND t2.`status` &lt;&gt; 3 ",
                        "AND t2.is_last = 1 ",
                        "<when test='studentName!=null and studentName!=&apos;&apos; '>",
                            "and t5.name like '%${studentName}%'",
                        "</when>",
                        "<when test='schoolIdStr!=null and schoolIdStr!=&apos;&apos; '>",
                            "and t2.school_id in(${schoolIdStr})",
                        "</when>",
                        "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
                            "and t4.year_class_id in(${yearClassIdStr})",
                        "</when>",
                        "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
                            "and t4.teacher_id = ${teacherId}",
                        "</when>",
                        "<when test='gradeId!=null and gradeId!=&apos;&apos; '>",
                            "and t2.grade_id = ${gradeId}",
                        "</when>",
                        "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
                            "and t4.course_type_id = ${classTypeId}",
                        "</when>",
                      ") AS t01 ",
                    ") AS t ",
                    "WHERE",
            "1 = 1 ",
            "and lesson_num &lt;= ${lessonNum}",
            "AND (((right_num + amend_num ) &lt; lowest_shutnum)",
            //" OR (( right_num / lowest_shutnum )* 100 &lt; pass_rade and not_brush = 0)",//取消复刷
            ")",
            //"<when test='isHistory==0'>",
            //    "AND ( lesson_num = ${lessonNum} OR(lesson_num &lt; ${lessonNum} AND is_finish = 0 ))",
            //"</when>",
            //"<when test='isHistory==1'>",
            //    "and lesson_num = ${lessonNum} AND is_finish = 0",
            //"</when>",
            "GROUP BY year_part,quarter_num,student_id,lesson_num",
            "HAVING 1=1 ",
            "<when test='count!=null and count!=&apos;&apos; '>",
            " AND brush_count = ${count} ",
            "</when>",
            " AND brush_count &lt; 3",
            "ORDER BY lesson_num,student_id asc",
    "</script>"})
    public IPage<ChaPlan> getChaPanAddList(IPage<?> page,
                                           @Param("yearPart") String yearPart,
                                           @Param("quarterNum") String quarterNum,
                                           @Param("schoolIdStr") String schoolIdStr,
                                           @Param("teacherId") String teacherId,
                                           @Param("gradeId") String gradeId,
                                           @Param("yearClassIdStr") String yearClassIdStr,
                                           @Param("classTypeId") String classTypeId,
                                           @Param("lessonNum") String lessonNum,
                                           @Param("isHistory") Integer isHistory,
                                           @Param("status") String status,
                                           @Param("studentName") String studentName,
                                           @Param("subjectsId") Long subjectsId,
                                           @Param("courseVersionId") Long courseVersionId,
                                           @Param("count") String count,
                                           @Param("taskCategoryId") Integer taskCategoryId);

    @Select({"<script>",
            "<when test='isIncludeFirstCourse == 1'>",
                "WITH record_course_with01 as (select id,year_part,`quarter`,subjects_id,student_id from xmy_erp_db.record_course where year_part = ${yearPart} and `quarter` = ${quarterNum} and lesson_num =1  and lesson_type =1 and course_type =1 and deleted =0 GROUP BY student_id)",
            "</when>",
            "SELECT",
                    "t02.*,",
                    "<when test='type == 6'>",
                        "t01.pid AS schoolPid,",
                        "t01.school_name,",
                    "</when>",
                    "IFNULL( SUM( lowest_shutnum ), 0 ) AS lowest_shutnum_all,",
                    "IFNULL( SUM( right_num ), 0 ) AS right_num_all,",
                    "<when test='rightNumStartDate != &apos;&apos; and rightNumEndDate != &apos;&apos;'>",
                        "SUM( right_num_date_no_sum ) AS right_num_date,",
                    "</when>",
                    "<when test='rightNumStartDate == &apos;&apos; and rightNumEndDate == &apos;&apos;'>",
                        "0 AS right_num_date,",
                    "</when>",
                    "SUM( amend_num ) AS amend_num_all,",
                    "SUM( lowest_shutnum - right_num ) AS error_num_all,",
                    "SUM( CASE WHEN (lowest_shutnum &lt;&gt; 0 AND lowest_shutnum is not null) THEN 1 ELSE 0 END ) AS show_pass_num,",
                    "SUM( CASE WHEN yet_pass_num_temp &gt;=student_all_shutnum and student_all_shutnum &gt; 0 THEN 1 ELSE 0 END ) AS yet_pass_num,",
                    "SUM( CASE WHEN not_pass_num_temp &gt;0 THEN 1 ELSE 0 END ) AS not_pass_num,",
                    "SUM( CASE WHEN not_brush_num_temp &gt;0 THEN 1 ELSE 0 END ) AS not_brush_num,",
                    "SUM( CASE WHEN again_brush_num_temp &gt;0 THEN 1 ELSE 0 END ) AS again_brush_num,",
                    "SUM( CASE WHEN date_pass_num_in &gt; 0 THEN 1 ELSE 0 END ) AS date_pass_num, ",
                    "SUM( CASE WHEN yet_finish_count_temp &gt;=student_all_shutnum and student_all_shutnum &gt; 0 THEN 1 ELSE 0 END ) AS yet_finish_count,",
                    "SUM( CASE WHEN date_yet_finish_count_temp &gt;=student_all_shutnum and student_all_shutnum &gt; 0 THEN 1 ELSE 0 END ) AS date_yet_finish_count, ",
                    "SUM( CASE WHEN rebrush_count_temp &gt; 0 THEN 1 ELSE 0 END ) AS rebrush_count,",
                    "SUM( CASE WHEN yet_rebrush_count_temp &gt; 0 THEN 1 ELSE 0 END ) AS yet_rebrush_count, ",
                    "SUM( CASE WHEN date_yet_rebrush_count_temp &gt; 0 THEN 1 ELSE 0 END ) AS date_yet_rebrush_count, ",
                    "SUM( CASE WHEN again_amend_num_temp &gt; 0 THEN 1 ELSE 0 END ) AS again_amend_num, ",
                    "SUM( CASE WHEN again_amend_num_temp2 &gt; 0 THEN 1 ELSE 0 END ) AS again_amend_num2, ",
                    "SUM( CASE WHEN yet_finish_count_temp2 &gt;=student_all_shutnum and student_all_shutnum &gt; 0 THEN 1 ELSE 0 END ) AS yet_finish_count2,",
                    "SUM( CASE WHEN date_yet_finish_count_temp2 &gt;=student_all_shutnum and student_all_shutnum &gt; 0 THEN 1 ELSE 0 END ) AS date_yet_finish_count2, ",
                    "SUM( CASE WHEN again_brush_num_temp2 &gt; 0 THEN 1 ELSE 0 END ) AS again_brush_num2, ",
                    "SUM( CASE WHEN not_again_brush_num_temp &gt; 0 THEN 1 ELSE 0 END ) AS not_again_brush_count, ",
//                    "SUM( CASE WHEN yet_again_brush_num_temp &gt;= student_all_shutnum AND student_all_shutnum &gt; 0 THEN 1 ELSE 0 END ) AS yet_again_brush_count, ",
//                    "SUM( CASE WHEN date_yet_again_brush_num_temp &gt;= student_all_shutnum AND student_all_shutnum &gt; 0 THEN 1 ELSE 0 END ) AS date_yet_again_brush_count ",
                    "SUM( CASE WHEN yet_again_brush_num_temp &gt; 0 THEN 1 ELSE 0 END ) AS yet_again_brush_count, ",
                    "SUM( CASE WHEN date_yet_again_brush_num_temp &gt; 0 THEN 1 ELSE 0 END ) AS date_yet_again_brush_count ",

                    "<when test='type == 6'>",
                        "FROM ( SELECT * FROM xmy_erp_db.school_quarter WHERE year_part = ${yearPart} AND quarter_num = ${quarterNum} AND deleted = 0) AS t01",
                        "LEFT JOIN (",
                    "</when>",
                    "<when test='type != 6'>",
                        "FROM (" ,
                    "</when>",
                    "SELECT",
                      "school_id,",
                      "year_part,",
                      "quarter_num,",
                      "grade_id,",
                      "grade_name,",
                      "teacher_id,",
                      "teacher_name,",
                      "class_type_id,",
                      "year_class_id,",
                      "student_id,",
                      "lesson_num,",
                      "if(brush_count=0,1,brush_count) as brush_count,",
                      "add_date,",
                      "SUM( lowest_shutnum ) AS lowest_shutnum,",
                      "pass_rade, ",
                      "<when test='rightNumStartDate != &apos;&apos; and rightNumEndDate != &apos;&apos;'>",
                      "SUM( CASE WHEN add_date BETWEEN '${rightNumStartDate}' AND '${rightNumEndDate}' THEN right_num ELSE 0 END ) AS right_num_date_no_sum,",
                      "</when>",
                      "<when test='rightNumStartDate == &apos;&apos; and rightNumEndDate == &apos;&apos;'>",
                      "0 AS right_num_date_no_sum,",
                      "</when>",
                      "SUM( right_num ) AS right_num,",
                      "SUM( amend_num ) AS amend_num,",
                      "SUM( CASE WHEN lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL THEN 1 ELSE 0 END ) AS student_all_shutnum,",
//                      "SUM( CASE WHEN ( ( right_num + amend_num ) &gt;= lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ) THEN 1 ELSE 0 END ) AS yet_pass_num_temp,",
//                      "SUM( CASE WHEN ( ( right_num + amend_num ) &lt; lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ) THEN 1 ELSE 0 END ) AS not_pass_num_temp,",
//                      "SUM( CASE WHEN ( (right_num / lowest_shutnum )* 100 &gt;= pass_rade AND lowest_shutnum &lt;&gt; 0 and lowest_shutnum IS NOT NULL) THEN 1 ELSE 0 END ) AS yet_pass_num_temp,",
//                      "SUM( CASE WHEN ( ( right_num / lowest_shutnum )* 100 &lt; pass_rade) AND lowest_shutnum &lt;&gt; 0 and lowest_shutnum IS NOT NULL THEN 1 ELSE 0 END ) AS not_pass_num_temp,",
//                      "SUM( CASE WHEN ( ( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND (right_num + amend_num &gt;= lowest_shutnum) AND lowest_shutnum &lt;&gt; 0 and lowest_shutnum IS NOT NULL) THEN 1 ELSE 0 END ) AS yet_pass_num_temp,",
                      "SUM( CASE WHEN ((( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR ( brush_count &gt;= 2 AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR (not_brush = 1 and ( right_num + amend_num ) &gt;= lowest_shutnum)) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL THEN 1 ELSE 0 END ) AS yet_pass_num_temp,",
//                      "SUM( CASE WHEN ( ((( right_num / lowest_shutnum )* 100 &lt; pass_rade) OR ((right_num / lowest_shutnum * 100 &gt;= pass_rade ) AND (right_num + amend_num &lt; lowest_shutnum)))) AND lowest_shutnum &lt;&gt; 0 and lowest_shutnum IS NOT NULL THEN 1 ELSE 0 END ) AS not_pass_num_temp,",
                      "SUM( CASE WHEN (( not_brush = 0 and brush_count &lt;= 1 AND ( right_num / lowest_shutnum )* 100 &lt; pass_rade) OR (not_brush = 0 and brush_count &gt;= 2 AND ( right_num + amend_num ) &lt; lowest_shutnum ) OR (( right_num / lowest_shutnum )* 100 &gt;= pass_rade  AND ( right_num + amend_num ) &lt; lowest_shutnum ) OR (not_brush = 1 and ( right_num + amend_num ) &lt; lowest_shutnum )) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL THEN 1 ELSE 0 END ) AS not_pass_num_temp,",
                      "SUM( CASE WHEN ( brush_count = 0 AND ( right_num = 0 AND amend_num = 0 AND lowest_shutnum IS NOT NULL)) THEN 1 ELSE 0 END ) AS not_brush_num_temp,",
                      "SUM( CASE WHEN ( brush_count &gt; 0 AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL) THEN 1 ELSE 0 END ) AS yet_finish_count_temp,",
//                      "SUM( CASE WHEN ( brush_count &gt;= 1 AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade ) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum is not null) THEN 1 ELSE 0 END ) AS again_brush_num_temp,",
//                      "SUM( CASE WHEN ( brush_count &gt;= 1 AND brush_count &lt;= 2 AND (right_num + amend_num ) &lt; lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum is not null) THEN 1 ELSE 0 END ) AS again_brush_num_temp,",
                      "SUM( CASE WHEN (not_brush = 0 and brush_count &gt;= 1 AND (brush_count &lt; 2 OR (right_num + amend_num &lt; lowest_shutnum)) AND ((( right_num / lowest_shutnum )* 100 &lt; pass_rade) OR ((right_num / lowest_shutnum * 100 &gt;= pass_rade) AND (right_num + amend_num &lt; lowest_shutnum))) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum is not null) THEN 1 ELSE 0 END ) AS again_brush_num_temp,",
//                      "SUM( CASE WHEN ( right_num + amend_num ) &gt;= lowest_shutnum AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' THEN 1 ELSE 0 END ) AS date_pass_num_in, ",
//                      "SUM( CASE WHEN ( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' THEN 1 ELSE 0 END ) AS date_pass_num_in, ",
//                      "SUM( CASE WHEN ( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND (right_num + amend_num &gt;= lowest_shutnum) AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' THEN 1 ELSE 0 END ) AS date_pass_num_in, ",
                        "SUM( CASE WHEN ((( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR ( brush_count &gt;= 2 AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR (not_brush = 1 and ( right_num + amend_num ) &gt;= lowest_shutnum)) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' THEN 1 ELSE 0 END ) AS date_pass_num_in,",
                      "SUM( CASE WHEN ( brush_count &gt; 0 AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}') THEN 1 ELSE 0 END ) AS date_yet_finish_count_temp,",
                      "SUM( CASE WHEN ( is_first = 1 AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade ) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ) THEN 1 ELSE 0 END ) AS rebrush_count_temp,",
                      "SUM( CASE WHEN ( is_first = 1 AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade ) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL and again_brush_id is not null) THEN 1 ELSE 0 END ) AS yet_rebrush_count_temp, ",
                      "SUM( CASE WHEN ( is_first = 1 AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade ) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL and again_brush_id is not null AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ) THEN 1 ELSE 0 END ) AS date_yet_rebrush_count_temp, ",
                      "SUM( CASE WHEN ( brush_count &gt;= 1 AND ( right_num + amend_num ) &lt; lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ) THEN 1 ELSE 0 END ) AS again_amend_num_temp, ",
                      "SUM( CASE WHEN ( brush_count = 1 AND ( right_num + amend_num ) &lt; lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ) THEN 1 ELSE 0 END ) AS again_amend_num_temp2, ",// 需修正2（第一次刷题）
                      "SUM( CASE WHEN ( brush_count = 1 AND (right_num + amend_num) &gt;= lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ) THEN 1 ELSE 0 END ) AS yet_finish_count_temp2,",// 已完成2（第一次刷题，正确＋修正>=应通关）
                      "SUM( CASE WHEN ( brush_count = 1 AND (right_num + amend_num) &gt;= lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ) THEN 1 ELSE 0 END ) AS date_yet_finish_count_temp2, ",// 已完成2（第一次刷题，正确＋修正>=应通关）
                      "SUM( CASE WHEN (( brush_count &gt;= 1 AND (brush_count &lt; 2 OR ( right_num + amend_num &lt; lowest_shutnum )) AND (((right_num / lowest_shutnum )* 100 &lt; pass_rade ) OR (( right_num / lowest_shutnum * 100 &gt;= pass_rade ) AND ( right_num + amend_num &lt; lowest_shutnum ))) OR brush_count &gt;= 2 ) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ) THEN 1 ELSE 0 END ) AS again_brush_num_temp2, ",// 复刷完成率需复刷
                      "SUM( CASE WHEN ( ( brush_count &gt;= 1 AND (( right_num + amend_num ) &lt; lowest_shutnum OR ( right_num / lowest_shutnum )* 100 &lt; pass_rade ))) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL THEN 1 ELSE 0 END ) AS not_again_brush_num_temp,",
                      "SUM( CASE WHEN ( ( brush_count &gt;= 2 AND (( right_num + amend_num ) &gt;= lowest_shutnum AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade ))) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL THEN 1 ELSE 0 END ) AS yet_again_brush_num_temp, ",
                      "SUM( CASE WHEN ( ( brush_count &gt;= 2 AND (( right_num + amend_num ) &gt;= lowest_shutnum AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade ))) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' THEN 1 ELSE 0 END ) AS date_yet_again_brush_num_temp ",

            "FROM",
                      "(",
                      "SELECT",
                        "t01.school_id,",
                        "t01.year_part,",
                        "t01.quarter_num,",
                        "t02.course_version_id,",
                        "t01.grade_id,",
                        "t01.grade_name,",
                        "t01.teacher_id,",
                        "t01.teacher_name,",
                        "t01.class_type_id,",
                        "t01.year_class_id,",
                        "t01.student_id,",
                        "t02.task_course_num AS lesson_num,",
                        "t02.not_brush,",
                        "t03.is_first,",
                        "t03.is_last,",
                        "t04.id as again_brush_id,",
                        "IFNULL( t03.brush_count,0) as brush_count,",
                        "(CASE WHEN t03.right_num IS NOT NULL AND t03.pass_rade &gt; 0 and (t03.right_num + t03.amend_num ) &gt;= t03.lowest_shutnum AND ( t03.right_num / t03.lowest_shutnum )* 100 &gt;= t03.pass_rade THEN t03.lowest_shutnum ELSE t02.lowest_shutnum END ) AS lowest_shutnum,",
                        "IFNULL( t03.right_num, 0 ) AS right_num,",
                        "IFNULL( t03.amend_num, 0 ) AS amend_num,",
                        "t03.add_date, ",
                        "IFNULL(t03.pass_rade ,t02.pass_rade) as pass_rade ",
                      "FROM",
                        "(",

                        "<when test= 'moldType == 1'>",
                            "SELECT",
                            "t1.*,",
                            "t1.class_type_id_new AS class_type_id,",
                            "t2.teacher_id,",
                            "t2.`name` AS grade_name,",
                            "sff.`name` AS teacher_name",
                            "FROM",
                            "xmy_erp_db.student_grade AS t1",
                            "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id ",
                            "INNER JOIN xmy_erp_db.staff AS sff ON sff.id = t2.teacher_id",
                            "INNER JOIN per_student_account AS t3 ON t1.student_id = t3.student_id",
                            "LEFT JOIN xmy_erp_db.rade_exclude_student AS t4 ON t4.classify_id = 0 AND t4.deleted = 0 AND t4.type = 2 AND t1.student_id = t4.student_id AND t1.year_part = t4.year_part AND t1.quarter_num = t4.quarter_num AND ( FIND_IN_SET( t1.subjects_id, t4.subjects_ids ) OR t4.subjects_ids IS NULL ) AND ( FIND_IN_SET( t1.school_id, t4.school_ids ) OR t4.school_ids IS NULL ) ",
                            "WHERE",
                            "t1.year_part = ${yearPart} ",
                            "AND t1.quarter_num = ${quarterNum} ",
                            "AND t1.lesson_type = 1 ",
                            "AND t1.deleted = 0 ",
                            "AND t1.subjects_id IN (${subjectsId}) ",
                            "AND t1.is_last = 1 ",
                            "<when test='include!=null and include!=&apos;&apos; and isIncludeFirstCourse == 0'>",
                                "<when test='include == 0'>",
                                    "and t4.id is null ",
                                "</when>",
                                "<when test='include == 1'>",
                                    "and t4.id is not null ",
                                "</when>",
                            "</when>",
                            "<when test='isBeforQuarter == 0 and readingType == 1'>",
                                "AND t1.reading_status IN (1,5) ",
                            "</when>",
                            "<when test='isBeforQuarter == 1 and readingType == 1'>",
                                "AND t1.reading_status IN (1,5)",
                            "</when>",
                            "<when test='readingType == 2'>",
                                "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and use_course_count > 0)) ",
                            "</when>",
                            "AND t1.STATUS &lt;&gt; 3 ",
                            "AND t1.deleted = 0 ",
//                            "<when test='schoolIdStr!=null and schoolIdStr!=&apos;&apos; and (type == 2 || type == 4)'>",
//                                "AND t1.school_id in(${schoolIdStr}) ",
//                            "</when>",
//                            "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
//                                "AND t2.teacher_id in(${teacherId}) ",
//                            "</when>",
//                            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
//                                "AND t2.year_class_id in(${yearClassIdStr}) ",
//                            "</when>",
//                            "<when test='yearClassIdStr==null or yearClassIdStr==&apos;&apos; '>",
//                                "AND t2.year_class_id &lt; 13 ",
//                            "</when>",

                                "and(",
                                "(",
                                "t1.school_id IN (${schoolIdStr})",
                                "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos;'>",
                                "AND t2.year_class_id IN (${yearClassIdStr})",
                                "</when>",

                                "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
                                "AND t2.teacher_id IN (${teacherId})",
                                "</when>",

                                ")",
                                "or",
                                "(",
                                "t1.school_id IN (${leadSchoolIds})",
                                "and t2.year_class_id IN (${leadYearClassIds})",
                                "and t2.teacher_id IN (${leadTeacherId})",
                                ")",
                                ")",

                            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
                                "AND t1.class_type_id_new IN (${classTypeId}) ",
                            "</when>",
                            "<when test='type ==3'>",
                                "AND t2.teacher_id in(select admin_id from xmy_erp_db.role_admin where role_id = 1568160887369994242) ",
                            "</when>",
                            "<when test='trackId!=null and trackId!=&apos;&apos; and type ==1'>",
                                "AND t2.teacher_id in(select sourse_id from xmy_erp_db.track_detail where deleted = 0 and track_id =#{trackId}) ",
                            "</when>",
                            "<when test='trackId!=null and trackId!=&apos;&apos; and type ==4'>",
                                "AND t1.school_id in(select sourse_id from xmy_erp_db.track_detail where deleted = 0 and track_id =#{trackId}) ",
                            "</when>",
                            "<when test='name!=null and name!=&apos;&apos; '>",
                                "AND sff.`name` LIKE '%${name}%' ",
                            "</when>",
                            "GROUP BY student_id",
                        "</when>",

                        "<when test= 'moldType == 2'>",
                            "SELECT",
                            "t02.*, ",
                            "t02.class_type_id_new AS class_type_id,",
                            "t03.teacher_id,",
                            "t03.`name` AS grade_name,",
                            "staff.`name` AS teacher_name ",
                            "FROM",
                            "(",
                                "SELECT",
                                "t1.school_id,",
                                "t1.old_teacher_id AS teacher_id,",
                                "t1.student_id,",
                                "t1.`status`,",
                                "t1.reach_type,",
                                "t1.old_grade_id AS grade_id,",
                                "t1.subjects_id,",
                                "t1.year_class_id,",
                                "t1.time_start,",
                                "t1.time_end,",
                                "t1.course_type, ",
                                "t1.lesson_num,",
                                "t1.school_date,",
                                "t10.year_part,",
                                "t10.quarter_num ",
                                "FROM",
                                "xmy_erp_db.record_course AS t1 ",
                                "INNER JOIN xmy_erp_db.grade AS t10 ON t1.grade_id = t10.id AND t10.is_rebrush = 0 ",
                                "WHERE",
                                "t1.deleted = 0 ",
                                "AND t1.year_part = ${yearPart} ",
                                "AND t1.`quarter` = ${quarterNum} ",
                                "AND t1.`lesson_type` = 3 ",
                                "AND t1.old_teacher_id IS NOT NULL ",
                                "AND ((t1.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ) OR ( t1.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' AND t1.course_type = 7 )) ",

                                "UNION ALL ",

                                "SELECT",
                                "t4.school_id,",
                                "t4.teacher_id,",
                                "t1.student_id,",
                                "t5.`status`,",
                                "t5.reach_type,",
                                "t6.grade_id,",
                                "t2.subjects_id,",
                                "t4.year_class_id,",
                                "t2.time_start,",
                                "t2.time_end,",
                                "1 AS course_type, ",
                                "t2.lesson_num,",
                                "t2.school_date, ",
                                "t10.year_part,",
                                "t10.quarter_num ",
                                "FROM",
                                "xmy_erp_db.${courseSchedulingDetailName} AS t2",
                                "INNER JOIN xmy_erp_db.grade AS t10 ON t2.grade_id = t10.id AND t10.is_rebrush = 0 ",
                                "INNER JOIN xmy_erp_db.student_grade AS t1 ON t2.year_part = t1.year_part ",
                                "AND t2.`quarter` = t1.quarter_num ",
                                "AND t2.deleted = t1.deleted ",
                                "AND t2.grade_id = t1.grade_id ",
                                "AND t2.lesson_type = t1.lesson_type ",
                                "<when test='isBeforQuarter == 0 and readingType == 1'>",
                                    "AND t1.reading_status IN (1,5) ",
                                "</when>",
                                "<when test='isBeforQuarter == 1 and readingType == 1'>",
                                    "AND t1.reading_status IN (1,5)",
                                "</when>",
                                "<when test='readingType == 2'>",
                                    "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and t1.use_course_count > 0)) ",
                                "</when>",
                                "AND t1.`status` = 1",
                                "INNER JOIN xmy_erp_db.student_grade AS t6 ON t6.year_part = t1.year_part ",
                                "AND t6.`quarter_num` = t1.quarter_num ",
                                "AND t6.deleted = t1.deleted ",
                                "AND t6.subjects_id = t1.subjects_id ",
                                "AND t6.`student_id` = t1.student_id ",
                                "AND t6.lesson_type = 1 ",
                                "<when test='isBeforQuarter == 0 and readingType == 1'>",
                                    "AND t6.reading_status IN (1,5) ",
                                "</when>",
                                "<when test='isBeforQuarter == 1 and readingType == 1'>",
                                    "AND t6.reading_status IN (1,5)",
                                "</when>",
                                "<when test='readingType == 2'>",
                                    "AND ((t6.reading_status IN (1,5)) or (t6.reading_status in(3,4) and t6.use_course_count > 0)) ",
                                "</when>",
                                "AND t6.`status` = 1",
                                "and t2.end_date_time &gt;= t6.created_at",
                                "LEFT JOIN xmy_erp_db.repair_course AS t3 ON t3.out_scheduling_detail_id = t2.id AND t3.deleted = 0",
                                "AND t3.student_id = t1.student_id",
                                "LEFT JOIN xmy_erp_db.grade AS t4 ON t6.grade_id = t4.id",
                                "LEFT JOIN xmy_erp_db.record_course AS t5 ON t5.scheduling_detail_id = t2.id ",
                                "AND t5.student_id = t1.student_id ",
                                "AND t5.deleted = 0 ",
                                "WHERE",
                                "t2.year_part = ${yearPart} ",
                                "AND t2.`quarter` = ${quarterNum} ",
                                "AND t2.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
                                "AND t2.lesson_type = 3 ",
                                "AND t2.deleted = 0 ",
                                "AND t2.`status` &lt;&gt; 2 ",
                                "AND t3.id IS NULL ",
                                "GROUP BY",
                                "t2.id,",
                                "t1.school_id,",
                                "t1.subjects_id,",
                                "t1.student_id,",
                                "t1.lesson_type ",
                            ") AS t01",
                            "INNER JOIN xmy_erp_db.student_grade AS t02 ON t01.student_id = t02.student_id ",
                            "AND t01.subjects_id = t02.subjects_id ",
                            "AND t01.year_part = t02.year_part ",
                            "AND t01.quarter_num = t02.quarter_num ",
                            "AND t02.lesson_type = 1 ",
                            "AND t02.deleted = 0 ",
                            "AND t02.is_last = 1 ",
                            "INNER JOIN xmy_erp_db.grade AS t03 ON t02.grade_id = t03.id ",
                            "INNER JOIN xmy_erp_db.staff ON staff.id = t03.teacher_id ",
                            "LEFT JOIN xmy_erp_db.rade_exclude_student AS t04 ON t04.classify_id = 0 ",
                            "AND t04.deleted = 0 ",
                            "AND t04.type = 2 ",
                            "AND t02.student_id = t04.student_id ",
                            "AND t02.year_part = t04.year_part ",
                            "AND t02.quarter_num = t04.quarter_num ",
                            "AND ( FIND_IN_SET( t02.subjects_id, t04.subjects_ids ) OR t04.subjects_ids IS NULL ) ",
                            "AND ( FIND_IN_SET( t02.school_id, t04.school_ids ) OR t04.school_ids IS NULL ) ",
                            "INNER JOIN per_student_account AS t05 ON t05.student_id = t01.student_id ",
                            "LEFT JOIN xmy_erp_db.cha_study_plan AS csp ON t01.student_id = csp.student_id ",
                            "AND csp.subjects_id = t01.subjects_id ",
                            "AND csp.lesson_type = 3 ",
                            "AND csp.`status` = 1 ",
                            "AND csp.year_part = ${yearPart}",
                            "AND csp.quarter_num = ${quarterNum} ",
                            "AND school_date BETWEEN csp.start_task_date AND csp.end_task_date ",
                            "AND DATE(csp.created_at) &lt; school_date ",
                            "WHERE ",
//                            "((t01.`status` = 1 AND course_type &lt;&gt; 7 ) OR ( course_type = 7 )) ",
                            "t01.`status` = 1 ",
                            "AND t02.`status` &lt;&gt; 3 ",
                            "AND csp.student_id IS NULL",
                            "AND t03.year_part = ${yearPart} ",
                            "AND t03.quarter_num = ${quarterNum} ",
                            "AND t03.lesson_type = 1 ",
                            "AND t03.subjects_id IN (${subjectsId}) ",
//                            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
//                                "AND t03.year_class_id in(${yearClassIdStr}) ",
//                            "</when>",
//                            "<when test='yearClassIdStr==null or yearClassIdStr==&apos;&apos; '>",
//                                "AND t03.year_class_id &lt; 13 ",
//                            "</when>",
                            "<when test='include!=null and include!=&apos;&apos; and isIncludeFirstCourse == 0'>",
                                "<when test='include == 0'>",
                                    "and t04.id IS NULL  ",
                                "</when>",
                                "<when test='include == 1'>",
                                    "and t04.id IS NOT NULL  ",
                                "</when>",
                            "</when>",
                            "<when test='isBeforQuarter == 0 and readingType == 1'>",
                                "AND t02.reading_status IN (1,5) ",
                            "</when>",
                            "<when test='isBeforQuarter == 1 and readingType == 1'>",
                                "AND t02.reading_status IN (1,5)",
                            "</when>",
                            "<when test='readingType == 2'>",
                                "AND ((t02.reading_status IN (1,5)) or (t02.reading_status in(3,4) and t02.use_course_count > 0)) ",
                            "</when>",
//                            "<when test='schoolIdStr!=null and schoolIdStr!=&apos;&apos; and (type == 2 || type == 4)'>",
//                                "AND t03.school_id in(${schoolIdStr}) ",
//                            "</when>",
//                            "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
//                                "AND t03.teacher_id in(${teacherId}) ",
//                            "</when>",
                            "and(",
                            "(",
                            "t03.school_id IN (${schoolIdStr})",
                            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos;'>",
                            "AND t03.year_class_id IN (${yearClassIdStr})",
                            "</when>",

                            "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
                            "AND t03.teacher_id IN (${teacherId})",
                            "</when>",

                            ")",
                            "or",
                            "(",
                            "t03.school_id IN (${leadSchoolIds})",
                            "and t03.year_class_id IN (${leadYearClassIds})",
                            "and t03.teacher_id IN (${leadTeacherId})",
                            ")",
                            ")",

                            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
                                "AND t02.class_type_id_new IN (${classTypeId}) ",
                            "</when>",
                            "<when test='type ==3'>",
                                "AND t03.teacher_id in(select admin_id from xmy_erp_db.role_admin where role_id = 1568160887369994242) ",
                            "</when>",
                            "<when test='trackId!=null and trackId!=&apos;&apos; and type ==1'>",
                                "AND t03.teacher_id in(select sourse_id from xmy_erp_db.track_detail where deleted = 0 and track_id =#{trackId}) ",
                            "</when>",
                            "<when test='trackId!=null and trackId!=&apos;&apos; and type ==4'>",
                                "AND t03.school_id in(select sourse_id from xmy_erp_db.track_detail where deleted = 0 and track_id =#{trackId}) ",
                            "</when>",
                            "<when test='name!=null and name!=&apos;&apos; '>",
                                "AND staff.`name` LIKE '%${name}%' ",
                            "</when>",
                            "GROUP BY student_id",
                        "</when>",

                        ") AS t01",
                        "<when test='isIncludeFirstCourse == 1'>",
                            "left JOIN record_course_with01 as t06 on t01.student_id = t06.student_id and t01.subjects_id = t06.subjects_id",
                        "</when>",
                        "LEFT JOIN ( SELECT * FROM edu_task WHERE deleted = 0 and task_category_id = ${taskCategoryId} and subjects_id IN (${subjectsId}) and task_course_num BETWEEN ${lessonNumStart} and ${lessonNum} ) AS t02 ON t01.year_part = t02.year_part ",
                        "AND t01.quarter_num = t02.quarter_num ",
                        "AND t01.subjects_id = t02.subjects_id ",
                        "AND t01.class_type_id = t02.class_type_id",
                        "AND t01.year_class_id = t02.year_class_id",
                        "<when test= 'inType == 2'>",
                        "inner",
                        "</when>",
                        "<when test= 'inType != 2'>",
                        "LEFT",
                        "</when>",
                        "JOIN (",
                        "SELECT",
                          "student_id,",
                          "add_date,",
                          "lesson_num_finish,",
                          "year_class_id,",
                          "course_version_id,",
                          "class_type_id,",
                          "year_part,",
                          "quarter_num,",
                          "IFNULL( lesson_num, 0 ) AS lesson_num,",
                          "right_num,",
                          "is_last,",
                          "is_first,",
                          "amend_num, ",
                          "pass_rade,",
                          "brush_count,",
                          "lowest_shutnum",
                        "FROM",
                          "cha_plan ",
                        "WHERE",
                          "year_part = ${yearPart} ",
                          "AND quarter_num = ${quarterNum} ",
                          "AND task_category_id = ${taskCategoryId} ",
                          "and deleted = 0",
                        ") AS t03 ON t01.year_part = t03.year_part ",
                        "AND t01.quarter_num = t03.quarter_num ",
                        "AND t01.student_id = t03.student_id ",
                        "AND t02.year_class_id = t03.year_class_id",
                        "AND t02.course_version_id = t03.course_version_id",
                        "AND t02.class_type_id = t03.class_type_id ",
                        "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
                            "and t01.subjects_id IN (${subjectsId})",
                        "</when>",
                        //"<when test='isAll == 0'>",
                        //    "AND t02.task_course_num = t03.lesson_num",
                        //    "AND t02.task_course_num = t03.lesson_num_finish",
                        //"</when>",
                        //"<when test='isAll == 1'>",
                        //    "AND t02.task_course_num = t03.lesson_num",
                        //    "and t03.is_last = 1",
                        //"</when>",
                        "AND t02.task_course_num = t03.lesson_num",
                        "<when test='radeType!=null and radeType == 1 '>",
                            "<when test='isAchieve!=null and isAchieve!=&apos;&apos; and isAchieve == 0'>",
                                "and t03.is_last = 1",
                            "</when>",
                            "<when test='isAchieve!=null and isAchieve!=&apos;&apos; and isAchieve == 1'>",
                                "and t03.is_first = 1",
                            "</when>",
                        "</when>",
                        "<when test='radeType!=null and (radeType == 2 or radeType == 3) '>",
                            "and t03.is_first = 1",
                        "</when>",

                        "LEFT JOIN ( ",
                            "SELECT",
                            "id,",
                            "student_id,",
                            "add_date,",
                            "lesson_num_finish,",
                            "year_class_id,",
                            "course_version_id,",
                            "class_type_id,",
                            "year_part,",
                            "quarter_num,",
                            "IFNULL( lesson_num, 0 ) AS lesson_num,",
                            "right_num,",
                            "is_last,",
                            "is_first,",
                            "amend_num,",
                            "pass_rade,",
                            "brush_count,",
                            "lowest_shutnum",
                            "FROM",
                            "cha_plan",
                            "WHERE",
                            "year_part = ${yearPart} ",
                            "AND quarter_num = ${quarterNum} ",
                            "AND task_category_id = ${taskCategoryId} ",
                            "AND deleted = 0",
                        ") AS t04 ON t04.year_part = t03.year_part ",
                        "AND t04.quarter_num = t03.quarter_num ",
                        "AND t04.student_id = t03.student_id ",
                        "AND t04.year_class_id = t03.year_class_id ",
                        "AND t04.course_version_id = t03.course_version_id ",
                        "AND t04.class_type_id = t03.class_type_id ",
                        "AND t04.lesson_num = t03.lesson_num ",
                        "and t04.is_last = 1 ",
                        "and t04.is_first = 0 ",
                        "where 1=1",
                        "<when test='include!=null and include!=&apos;&apos; and isIncludeFirstCourse == 1'>",
                            "<when test='include == 0'>",
                                "and t06.id is not null",
                            "</when>",
                            "<when test='include == 1'>",
                                "and t06.id is null",
                            "</when>",
                        "</when>",

                      ") AS t ",
                    "GROUP BY student_id ",
                    "<if test= 'isYearClass == 1'>",
                        ",year_class_id",
                    "</if>",
                    "<when test='type == 6'>",
                        ") AS t02 ON t01.school_id = t02.school_id ",
                    "</when>",
                    "<when test='type != 6'>",
                        ") AS t02 ",
                    "</when>",
                    "where 1=1",

//                    "<when test='schoolIdStr!=null and schoolIdStr!=&apos;&apos; and (type == 2)'>",
//                        "and school_id in(${schoolIdStr})",
//                    "</when>",
//                    "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
//                        "and year_class_id in(${yearClassIdStr})",
//                    "</when>",

                        "and(",
                        "(",
                        "t02.school_id IN (${schoolIdStr})",
                        "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos;'>",
                        "AND year_class_id IN (${yearClassIdStr})",
                        "</when>",

                        "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
                        "AND teacher_id IN (${teacherId})",
                        "</when>",

                        ")",
                        "or",
                        "(",
                        "t02.school_id IN (${leadSchoolIds})",
                        "and year_class_id IN (${leadYearClassIds})",
                        "and teacher_id IN (${leadTeacherId})",
                        ")",
                        ")",
                    "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
                        "and class_type_id IN (${classTypeId})",
                    "</when>",
                    "<when test='type ==3'>",
                    "  and teacher_id in(select admin_id from xmy_erp_db.role_admin where role_id = 1568160887369994242)",
                    "</when>",
                    "<when test='trackId!=null and trackId!=&apos;&apos; and type ==1'>",
                    "  and teacher_id in(select sourse_id from xmy_erp_db.track_detail where deleted = 0 and track_id =#{trackId})",
                    "</when>",
                    "<when test='trackId!=null and trackId!=&apos;&apos; and type ==4'>",
                    "  and school_id in(select sourse_id from xmy_erp_db.track_detail where deleted = 0 and track_id =#{trackId})",
                    "</when>",
                    "GROUP BY ",
                    "<if test= 'isYearClass == 1'>",
                    "year_class_id,",
                    "</if>",
                    "<when test='type == 1 or type == 3'>",
                    "teacher_id",
                    "</when>",
                    "<when test='type == 2'>",
                    "school_id,teacher_id",
                    "</when>",
                    "<when test='type == 4 or type == 6'>",
                        "school_id",
                    "</when>",
                    "<when test='listState == 1'>",
                        ",grade_id",
                    "</when>",
                    "<if test= 'isYearClass == 1'>",
//                        "HAVING year_class_id IS NOT NULL",
                    "</if>",
            "</script>"})
    public List<ChaPlan> getPassRadeList(@Param("yearPart") String yearPart,
                                         @Param("quarterNum") String quarterNum,
                                         @Param("schoolIdStr") String schoolIdStr,
                                         @Param("yearClassIdStr") String yearClassIdStr,
                                         @Param("type") String type,
                                         @Param("lessonNumStart") String lessonNumStart,
                                         @Param("lessonNum") String lessonNum,
                                         @Param("classTypeId") String classTypeId,
                                         @Param("readingType") String readingType,
                                         @Param("lessonNow") String lessonNow,
                                         @Param("isAll") String isAll,
                                         @Param("passDate") String passDate,
                                         @Param("passDateStart") String passDateStart,
                                         @Param("passDateEnd") String passDateEnd,
                                         @Param("subjectsId") String subjectsId,
                                         @Param("isBeforQuarter") String isBeforQuarter,
                                         @Param("readingStatusStr") String readingStatusStr,
                                         @Param("rightNumStartDate") String rightNumStartDate,
                                         @Param("rightNumEndDate") String rightNumEndDate,
                                         @Param("trackId") String trackId,
                                         @Param("isYearClass") Integer isYearClass,
                                         @Param("radeType") String radeType,
                                         @Param("listState") String listState,
                                         @Param("teacherId") String teacherId,
                                         @Param("name") String name,
                                         @Param("include") String include,
                                         @Param("inType") String inType,
                                         @Param("taskCategoryId") Integer taskCategoryId,
                                         @Param("isAchieve") String isAchieve,
                                         @Param("moldType") String moldType, // 1、正常通关率 2、到勤通关率
                                         @Param("courseSchedulingDetailName") String courseSchedulingDetailName,
                                         @Param("leadSchoolIds") String leadSchoolIds,
                                         @Param("leadSubjectsIds") String leadSubjectsIds,
                                         @Param("leadYearClassIds") String leadYearClassIds,
                                         @Param("leadTeacherId") Long leadTeacherId,
                                         @Param("isIncludeFirstCourse") String isIncludeFirstCourse
    );

    /**
     *已过刷题排班时间
     * @return
     */
    @Select({"<script>",
            "<when test= 'examSchedulingtType == 1'>",
                "WITH wi_tb01 AS ( ",
                "SELECT",
                "rc.student_id",
                "FROM",
                "xmy_erp_db.record_course AS rc where",
                "rc.subjects_id = ${subjectsId}",
                "AND rc.year_part = ${yearPart}",
                "AND rc.quarter = ${quarterNum}",
                "AND rc.lesson_type = 3 ",
                "AND rc.deleted = 0",
                "AND rc.course_type &lt;&gt; 7",
                "AND rc.school_date BETWEEN #{schoolDateStart} AND #{schoolDateEnd}",
//                "AND #{schoolDateEnd} ",
                ")",
            "<when test='isIncludeFirstCourse == 1'>",
            " ,record_course_with01 as (select id,year_part,`quarter`,subjects_id,student_id from xmy_erp_db.record_course where year_part = ${yearPart} and `quarter` = ${quarterNum} and lesson_num =1 and lesson_type =1 and course_type =1 and deleted =0 GROUP BY student_id)",
            "</when>",
            "</when>",

            "<when test= 'examSchedulingtType == 2'>",
            "WITH wi_tb01 AS (",
             "SELECT",
               " t1.student_id",
               " FROM",
                "xmy_erp_db.student_grade AS t1",
                "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id",
                "INNER JOIN xmy_erp_db.course_scheduling_detail AS t3 ON t1.grade_id = t3.grade_id and t3.deleted = 0",
              "  WHERE",
                "t1.year_part = ${yearPart}",
                "AND t1.quarter_num = ${quarterNum}",
                "and t1.deleted = 0",
                "AND t2.lesson_type = 3",
                "AND t1.reading_status = 1",
                "AND t1.subjects_id = ${subjectsId}",
                "AND t3.school_date BETWEEN #{schoolDateStart} AND #{schoolDateEnd}",
//                "AND '2025-04-20'",
                "GROUP BY",
               " t1.student_id",
             "  )",
            "<when test='isIncludeFirstCourse == 1'>",
              " ,record_course_with01 as (select id,year_part,`quarter`,subjects_id,student_id from xmy_erp_db.record_course where year_part = ${yearPart} and `quarter` = ${quarterNum} and lesson_num =1 and lesson_type =1 and course_type =1 and deleted =0 GROUP BY student_id)",
            "</when>",
            "</when>",

            "SELECT",
            "t02.*,",
            "<when test='type == 6'>",
            "t01.pid AS schoolPid,",
            "t01.school_name,",
            "</when>",
            "SUM( lowest_shutnum ) AS lowest_shutnum_all,",
            "SUM( right_num ) AS right_num_all,",
            "<when test='rightNumStartDate != &apos;&apos; and rightNumEndDate != &apos;&apos;'>",
            "SUM( right_num_date_no_sum ) AS right_num_date,",
            "</when>",
            "<when test='rightNumStartDate == &apos;&apos; and rightNumEndDate == &apos;&apos;'>",
            "0 AS right_num_date,",
            "</when>",
            "SUM( amend_num ) AS amend_num_all,",
            "SUM( lowest_shutnum - right_num ) AS error_num_all,",
            "SUM( CASE WHEN (lowest_shutnum &lt;&gt; 0 AND lowest_shutnum is not null) THEN 1 ELSE 0 END ) AS show_pass_num,",
            "SUM( CASE WHEN yet_pass_num_temp &gt;=student_all_shutnum and student_all_shutnum &gt; 0 THEN 1 ELSE 0 END ) AS yet_pass_num,",
            "SUM( CASE WHEN not_pass_num_temp &gt;0 THEN 1 ELSE 0 END ) AS not_pass_num,",
            "SUM( CASE WHEN not_brush_num_temp &gt;0 THEN 1 ELSE 0 END ) AS not_brush_num,",
            "SUM( CASE WHEN again_brush_num_temp &gt;0 THEN 1 ELSE 0 END ) AS again_brush_num,",
            "SUM( CASE WHEN date_pass_num_in &gt; 0 THEN 1 ELSE 0 END ) AS date_pass_num, ",
            "SUM( CASE WHEN yet_finish_count_temp &gt;=student_all_shutnum and student_all_shutnum &gt; 0 THEN 1 ELSE 0 END ) AS yet_finish_count,",
            "SUM( CASE WHEN date_yet_finish_count_temp &gt;=student_all_shutnum and student_all_shutnum &gt; 0 THEN 1 ELSE 0 END ) AS date_yet_finish_count, ",
            "SUM( CASE WHEN rebrush_count_temp &gt; 0 THEN 1 ELSE 0 END ) AS rebrush_count,",
            "SUM( CASE WHEN yet_rebrush_count_temp &gt; 0 THEN 1 ELSE 0 END ) AS yet_rebrush_count, ",
            "SUM( CASE WHEN date_yet_rebrush_count_temp &gt; 0 THEN 1 ELSE 0 END ) AS date_yet_rebrush_count, ",
            "SUM( CASE WHEN again_amend_num_temp &gt; 0 THEN 1 ELSE 0 END ) AS again_amend_num, ",
            "SUM( CASE WHEN again_amend_num_temp2 &gt; 0 THEN 1 ELSE 0 END ) AS again_amend_num2, ",
            "SUM( CASE WHEN yet_finish_count_temp2 &gt;=student_all_shutnum and student_all_shutnum &gt; 0 THEN 1 ELSE 0 END ) AS yet_finish_count2,",
            "SUM( CASE WHEN date_yet_finish_count_temp2 &gt;=student_all_shutnum and student_all_shutnum &gt; 0 THEN 1 ELSE 0 END ) AS date_yet_finish_count2, ",
            "SUM( CASE WHEN again_brush_num_temp2 &gt; 0 THEN 1 ELSE 0 END ) AS again_brush_num2, ",
            "SUM( CASE WHEN not_again_brush_num_temp &gt; 0 THEN 1 ELSE 0 END ) AS not_again_brush_count, ",
//                    "SUM( CASE WHEN yet_again_brush_num_temp &gt;= student_all_shutnum AND student_all_shutnum &gt; 0 THEN 1 ELSE 0 END ) AS yet_again_brush_count, ",
//                    "SUM( CASE WHEN date_yet_again_brush_num_temp &gt;= student_all_shutnum AND student_all_shutnum &gt; 0 THEN 1 ELSE 0 END ) AS date_yet_again_brush_count ",
            "SUM( CASE WHEN yet_again_brush_num_temp &gt; 0 THEN 1 ELSE 0 END ) AS yet_again_brush_count, ",
            "SUM( CASE WHEN date_yet_again_brush_num_temp &gt; 0 THEN 1 ELSE 0 END ) AS date_yet_again_brush_count ",

            "<when test='type == 6'>",
            "FROM ( SELECT * FROM xmy_erp_db.school_quarter WHERE year_part = ${yearPart} AND quarter_num = ${quarterNum} AND deleted = 0) AS t01",
            "LEFT JOIN (",
            "</when>",
            "<when test='type != 6'>",
            "FROM (" ,
            "</when>",
            "SELECT",
            "school_id,",
            "year_part,",
            "quarter_num,",
            "grade_id,",
            "grade_name,",
            "teacher_id,",
            "teacher_name,",
            "class_type_id,",
            "year_class_id,",
            "student_id,",
            "lesson_num,",
            "if(brush_count=0,1,brush_count) as brush_count,",
            "add_date,",
            "SUM( lowest_shutnum ) AS lowest_shutnum,",
            "pass_rade, ",
            "<when test='rightNumStartDate != &apos;&apos; and rightNumEndDate != &apos;&apos;'>",
            "SUM( CASE WHEN add_date BETWEEN '${rightNumStartDate}' AND '${rightNumEndDate}' THEN right_num ELSE 0 END ) AS right_num_date_no_sum,",
            "</when>",
            "<when test='rightNumStartDate == &apos;&apos; and rightNumEndDate == &apos;&apos;'>",
            "0 AS right_num_date_no_sum,",
            "</when>",
            "SUM( right_num ) AS right_num,",
            "SUM( amend_num ) AS amend_num,",
            "SUM( CASE WHEN lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL THEN 1 ELSE 0 END ) AS student_all_shutnum,",

            "SUM( CASE WHEN ((( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR ( brush_count &gt;= 2 AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR (not_brush = 1 and ( right_num + amend_num ) &gt;= lowest_shutnum)) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL THEN 1 ELSE 0 END ) AS yet_pass_num_temp,",
//                      "SUM( CASE WHEN ( ((( right_num / lowest_shutnum )* 100 &lt; pass_rade) OR ((right_num / lowest_shutnum * 100 &gt;= pass_rade ) AND (right_num + amend_num &lt; lowest_shutnum)))) AND lowest_shutnum &lt;&gt; 0 and lowest_shutnum IS NOT NULL THEN 1 ELSE 0 END ) AS not_pass_num_temp,",
            "SUM( CASE WHEN (( not_brush = 0 and brush_count &lt;= 1 AND ( right_num / lowest_shutnum )* 100 &lt; pass_rade) OR (not_brush = 0 and brush_count &gt;= 2 AND ( right_num + amend_num ) &lt; lowest_shutnum ) OR (( right_num / lowest_shutnum )* 100 &gt;= pass_rade  AND ( right_num + amend_num ) &lt; lowest_shutnum ) OR (not_brush = 1 and ( right_num + amend_num ) &lt; lowest_shutnum )) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL THEN 1 ELSE 0 END ) AS not_pass_num_temp,",
            "SUM( CASE WHEN ( brush_count = 0 AND ( right_num = 0 AND amend_num = 0 AND lowest_shutnum IS NOT NULL)) THEN 1 ELSE 0 END ) AS not_brush_num_temp,",
            "SUM( CASE WHEN ( brush_count &gt; 0 AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL) THEN 1 ELSE 0 END ) AS yet_finish_count_temp,",

            "SUM( CASE WHEN (not_brush = 0 and brush_count &gt;= 1 AND (brush_count &lt; 2 OR (right_num + amend_num &lt; lowest_shutnum)) AND ((( right_num / lowest_shutnum )* 100 &lt; pass_rade) OR ((right_num / lowest_shutnum * 100 &gt;= pass_rade) AND (right_num + amend_num &lt; lowest_shutnum))) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum is not null) THEN 1 ELSE 0 END ) AS again_brush_num_temp,",

            "SUM( CASE WHEN ((( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR ( brush_count &gt;= 2 AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR (not_brush = 1 and ( right_num + amend_num ) &gt;= lowest_shutnum)) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' THEN 1 ELSE 0 END ) AS date_pass_num_in,",
            "SUM( CASE WHEN ( brush_count &gt; 0 AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}') THEN 1 ELSE 0 END ) AS date_yet_finish_count_temp,",
            "SUM( CASE WHEN ( is_first = 1 AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade ) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ) THEN 1 ELSE 0 END ) AS rebrush_count_temp,",
            "SUM( CASE WHEN ( is_first = 1 AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade ) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL and again_brush_id is not null) THEN 1 ELSE 0 END ) AS yet_rebrush_count_temp, ",
            "SUM( CASE WHEN ( is_first = 1 AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade ) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL and again_brush_id is not null AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ) THEN 1 ELSE 0 END ) AS date_yet_rebrush_count_temp, ",
            "SUM( CASE WHEN ( brush_count &gt;= 1 AND ( right_num + amend_num ) &lt; lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ) THEN 1 ELSE 0 END ) AS again_amend_num_temp, ",
            "SUM( CASE WHEN ( brush_count = 1 AND ( right_num + amend_num ) &lt; lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ) THEN 1 ELSE 0 END ) AS again_amend_num_temp2, ",// 需修正2（第一次刷题）
            "SUM( CASE WHEN ( brush_count = 1 AND (right_num + amend_num) &gt;= lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ) THEN 1 ELSE 0 END ) AS yet_finish_count_temp2,",// 已完成2（第一次刷题，正确＋修正>=应通关）
            "SUM( CASE WHEN ( brush_count = 1 AND (right_num + amend_num) &gt;= lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ) THEN 1 ELSE 0 END ) AS date_yet_finish_count_temp2, ",// 已完成2（第一次刷题，正确＋修正>=应通关）
            "SUM( CASE WHEN (( brush_count &gt;= 1 AND (brush_count &lt; 2 OR ( right_num + amend_num &lt; lowest_shutnum )) AND (((right_num / lowest_shutnum )* 100 &lt; pass_rade ) OR (( right_num / lowest_shutnum * 100 &gt;= pass_rade ) AND ( right_num + amend_num &lt; lowest_shutnum ))) OR brush_count &gt;= 2 ) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ) THEN 1 ELSE 0 END ) AS again_brush_num_temp2, ",// 复刷完成率需复刷
            "SUM( CASE WHEN ( ( brush_count &gt;= 1 AND (( right_num + amend_num ) &lt; lowest_shutnum OR ( right_num / lowest_shutnum )* 100 &lt; pass_rade ))) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL THEN 1 ELSE 0 END ) AS not_again_brush_num_temp,",
            "SUM( CASE WHEN ( ( brush_count &gt;= 2 AND (( right_num + amend_num ) &gt;= lowest_shutnum AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade ))) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL THEN 1 ELSE 0 END ) AS yet_again_brush_num_temp, ",
            "SUM( CASE WHEN ( ( brush_count &gt;= 2 AND (( right_num + amend_num ) &gt;= lowest_shutnum AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade ))) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' THEN 1 ELSE 0 END ) AS date_yet_again_brush_num_temp ",

            "FROM",
            "(",
            "SELECT",
            "t01.school_id,",
            "t01.year_part,",
            "t01.quarter_num,",
            "t02.course_version_id,",
            "t01.grade_id,",
            "t01.grade_name,",
            "t01.teacher_id,",
            "t01.teacher_name,",
            "t01.class_type_id,",
            "t01.year_class_id,",
            "t01.student_id,",
            "t02.task_course_num AS lesson_num,",
            "t02.not_brush,",
            "t03.is_first,",
            "t03.is_last,",
            "t04.id as again_brush_id,",
            "IFNULL( t03.brush_count,0) as brush_count,",
            "(CASE WHEN t03.right_num IS NOT NULL AND t03.pass_rade &gt; 0 and (t03.right_num + t03.amend_num ) &gt;= t03.lowest_shutnum AND ( t03.right_num / t03.lowest_shutnum )* 100 &gt;= t03.pass_rade THEN t03.lowest_shutnum ELSE t02.lowest_shutnum END ) AS lowest_shutnum,",
            "IFNULL( t03.right_num, 0 ) AS right_num,",
            "IFNULL( t03.amend_num, 0 ) AS amend_num,",
            "t03.add_date, ",
            "IFNULL(t03.pass_rade ,t02.pass_rade) as pass_rade ",
            "FROM",
            "(",

            "<when test= 'moldType == 1'>",
            "SELECT",
            "t1.*,",
            "t1.class_type_id_new AS class_type_id,",
            "t2.teacher_id,",
            "t2.`name` AS grade_name,",
            "sff.`name` AS teacher_name",
            "FROM",
            "xmy_erp_db.student_grade AS t1",
            "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id ",
            "INNER JOIN xmy_erp_db.staff AS sff ON sff.id = t2.teacher_id",
            "INNER JOIN per_student_account AS t3 ON t1.student_id = t3.student_id",

            // 已过刷题排班和未到刷题排班
            "INNER JOIN wi_tb01 on t1.student_id = wi_tb01.student_id  ",

            "LEFT JOIN xmy_erp_db.rade_exclude_student AS t4 ON t4.classify_id = 0 AND t4.deleted = 0 AND t4.type = 2 AND t1.student_id = t4.student_id AND t1.year_part = t4.year_part AND t1.quarter_num = t4.quarter_num AND ( FIND_IN_SET( t1.subjects_id, t4.subjects_ids ) OR t4.subjects_ids IS NULL ) AND ( FIND_IN_SET( t1.school_id, t4.school_ids ) OR t4.school_ids IS NULL ) ",
            "WHERE",
            "t1.year_part = ${yearPart} ",
            "AND t1.quarter_num = ${quarterNum} ",
            "AND t1.lesson_type = 1 ",
            "AND t1.deleted = 0 ",
            "AND t1.subjects_id IN (${subjectsId}) ",
            "AND t1.is_last = 1 ",

            "<when test='include!=null and include!=&apos;&apos; and isIncludeFirstCourse == 0'>",
                "<when test='include == 0'>",
                "and t4.id is null ",
                "</when>",
                "<when test='include == 1'>",
                "and t4.id is not null ",
                "</when>",
            "</when>",

            "<when test='isBeforQuarter == 0 and readingType == 1'>",
            "AND t1.reading_status IN (1,5) ",
            "</when>",
            "<when test='isBeforQuarter == 1 and readingType == 1'>",
            "AND t1.reading_status IN (1,5)",
            "</when>",
            "<when test='readingType == 2'>",
            "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and use_course_count > 0)) ",
            "</when>",
            "AND t1.STATUS &lt;&gt; 3 ",
            "AND t1.deleted = 0 ",
//            "<when test='schoolIdStr!=null and schoolIdStr!=&apos;&apos; and (type == 2 || type == 4)'>",
//            "AND t1.school_id in(${schoolIdStr}) ",
//            "</when>",
//            "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
//            "AND t2.teacher_id in(${teacherId}) ",
//            "</when>",
//            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
//            "AND t2.year_class_id in(${yearClassIdStr}) ",
//            "</when>",
//            "<when test='yearClassIdStr==null or yearClassIdStr==&apos;&apos; '>",
//            "AND t2.year_class_id &lt; 13 ",
//            "</when>",

            "and(",
            "(",
            "t1.school_id IN (${schoolIdStr})",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos;'>",
            "AND t2.year_class_id IN (${yearClassIdStr})",
            "</when>",
            ")",
            "or",
            "(",
            "t1.school_id IN (${leadSchoolIds})",
            "and t2.year_class_id IN (${leadYearClassIds})",
            "and t2.teacher_id IN (${leadTeacherId})",
            ")",
            ")",

            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "AND t1.class_type_id_new IN (${classTypeId}) ",
            "</when>",
            "<when test='type ==3'>",
            "AND t2.teacher_id in(select admin_id from xmy_erp_db.role_admin where role_id = 1568160887369994242) ",
            "</when>",
            "<when test='trackId!=null and trackId!=&apos;&apos; and type ==1'>",
            "AND t2.teacher_id in(select sourse_id from xmy_erp_db.track_detail where deleted = 0 and track_id =#{trackId}) ",
            "</when>",
            "<when test='trackId!=null and trackId!=&apos;&apos; and type ==4'>",
            "AND t1.school_id in(select sourse_id from xmy_erp_db.track_detail where deleted = 0 and track_id =#{trackId}) ",
            "</when>",
            "<when test='name!=null and name!=&apos;&apos; '>",
            "AND sff.`name` LIKE '%${name}%' ",
            "</when>",
            "GROUP BY student_id",
            "</when>",

            "<when test= 'moldType == 2'>",
            "SELECT",
            "t02.*, ",
            "t02.class_type_id_new AS class_type_id,",
            "t03.teacher_id,",
            "t03.`name` AS grade_name,",
            "staff.`name` AS teacher_name ",
            "FROM",
            "(",
            "SELECT",
            "t1.school_id,",
            "t1.old_teacher_id AS teacher_id,",
            "t1.student_id,",
            "t1.`status`,",
            "t1.reach_type,",
            "t1.old_grade_id AS grade_id,",
            "t1.subjects_id,",
            "t1.year_class_id,",
            "t1.time_start,",
            "t1.time_end,",
            "t1.course_type, ",
            "t1.lesson_num,",
            "t1.school_date,",
            "t10.year_part,",
            "t10.quarter_num ",
            "FROM",
            "xmy_erp_db.record_course AS t1 ",
            "INNER JOIN xmy_erp_db.grade AS t10 ON t1.grade_id = t10.id AND t10.is_rebrush = 0 ",
            "WHERE",
            "t1.deleted = 0 ",
            "AND t1.year_part = ${yearPart} ",
            "AND t1.`quarter` = ${quarterNum} ",
            "AND t1.`lesson_type` = 3 ",
            "AND t1.old_teacher_id IS NOT NULL ",
            "AND ((t1.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ) OR ( t1.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' AND t1.course_type = 7 )) ",

            "UNION ALL ",

            "SELECT",
            "t4.school_id,",
            "t4.teacher_id,",
            "t1.student_id,",
            "t5.`status`,",
            "t5.reach_type,",
            "t6.grade_id,",
            "t2.subjects_id,",
            "t4.year_class_id,",
            "t2.time_start,",
            "t2.time_end,",
            "1 AS course_type, ",
            "t2.lesson_num,",
            "t2.school_date, ",
            "t10.year_part,",
            "t10.quarter_num ",
            "FROM",
            "xmy_erp_db.${courseSchedulingDetailName} AS t2",
            "INNER JOIN xmy_erp_db.grade AS t10 ON t2.grade_id = t10.id AND t10.is_rebrush = 0 ",
            "INNER JOIN xmy_erp_db.student_grade AS t1 ON t2.year_part = t1.year_part ",
            "AND t2.`quarter` = t1.quarter_num ",
            "AND t2.deleted = t1.deleted ",
            "AND t2.grade_id = t1.grade_id ",
            "AND t2.lesson_type = t1.lesson_type ",
            "<when test='isBeforQuarter == 0 and readingType == 1'>",
            "AND t1.reading_status IN (1,5) ",
            "</when>",
            "<when test='isBeforQuarter == 1 and readingType == 1'>",
            "AND t1.reading_status IN (1,5)",
            "</when>",
            "<when test='readingType == 2'>",
            "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and t1.use_course_count > 0)) ",
            "</when>",
            "AND t1.`status` = 1",
            "INNER JOIN xmy_erp_db.student_grade AS t6 ON t6.year_part = t1.year_part ",
            "AND t6.`quarter_num` = t1.quarter_num ",
            "AND t6.deleted = t1.deleted ",
            "AND t6.subjects_id = t1.subjects_id ",
            "AND t6.`student_id` = t1.student_id ",
            "AND t6.lesson_type = 1 ",
            "<when test='isBeforQuarter == 0 and readingType == 1'>",
            "AND t6.reading_status IN (1,5) ",
            "</when>",
            "<when test='isBeforQuarter == 1 and readingType == 1'>",
            "AND t6.reading_status IN (1,5)",
            "</when>",
            "<when test='readingType == 2'>",
            "AND ((t6.reading_status IN (1,5)) or (t6.reading_status in(3,4) and t6.use_course_count > 0)) ",
            "</when>",
            "AND t6.`status` = 1",
            "and t2.end_date_time &gt;= t6.created_at",
            "LEFT JOIN xmy_erp_db.repair_course AS t3 ON t3.out_scheduling_detail_id = t2.id AND t3.deleted = 0",
            "AND t3.student_id = t1.student_id",
            "LEFT JOIN xmy_erp_db.grade AS t4 ON t6.grade_id = t4.id",
            "LEFT JOIN xmy_erp_db.record_course AS t5 ON t5.scheduling_detail_id = t2.id ",
            "AND t5.student_id = t1.student_id ",
            "AND t5.deleted = 0 ",
            "WHERE",
            "t2.year_part = ${yearPart} ",
            "AND t2.`quarter` = ${quarterNum} ",
            "AND t2.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
            "AND t2.lesson_type = 3 ",
            "AND t2.deleted = 0 ",
            "AND t2.`status` &lt;&gt; 2 ",
            "AND t3.id IS NULL ",
            "GROUP BY",
            "t2.id,",
            "t1.school_id,",
            "t1.subjects_id,",
            "t1.student_id,",
            "t1.lesson_type ",
            ") AS t01",
            "INNER JOIN xmy_erp_db.student_grade AS t02 ON t01.student_id = t02.student_id ",
            "AND t01.subjects_id = t02.subjects_id ",
            "AND t01.year_part = t02.year_part ",
            "AND t01.quarter_num = t02.quarter_num ",
            "AND t02.lesson_type = 1 ",
            "AND t02.deleted = 0 ",
            "AND t02.is_last = 1 ",
            "INNER JOIN xmy_erp_db.grade AS t03 ON t02.grade_id = t03.id ",
            "INNER JOIN xmy_erp_db.staff ON staff.id = t03.teacher_id ",
            "LEFT JOIN xmy_erp_db.rade_exclude_student AS t04 ON t04.classify_id = 0 ",
            "AND t04.deleted = 0 ",
            "AND t04.type = 2 ",
            "AND t02.student_id = t04.student_id ",
            "AND t02.year_part = t04.year_part ",
            "AND t02.quarter_num = t04.quarter_num ",
            "AND ( FIND_IN_SET( t02.subjects_id, t04.subjects_ids ) OR t04.subjects_ids IS NULL ) ",
            "AND ( FIND_IN_SET( t02.school_id, t04.school_ids ) OR t04.school_ids IS NULL ) ",
            "INNER JOIN per_student_account AS t05 ON t05.student_id = t01.student_id ",
            "LEFT JOIN xmy_erp_db.cha_study_plan AS csp ON t01.student_id = csp.student_id ",
            "AND csp.subjects_id = t01.subjects_id ",
            "AND csp.lesson_type = 3 ",
            "AND csp.`status` = 1 ",
            "AND csp.year_part = ${yearPart}",
            "AND csp.quarter_num = ${quarterNum} ",
            "AND school_date BETWEEN csp.start_task_date AND csp.end_task_date ",
            "AND DATE(csp.created_at) &lt; school_date ",
            "WHERE ",
            "t01.`status` = 1 ",
            "AND t02.`status` &lt;&gt; 3 ",
            "AND csp.student_id IS NULL",
            "AND t03.year_part = ${yearPart} ",
            "AND t03.quarter_num = ${quarterNum} ",
            "AND t03.lesson_type = 1 ",
            "AND t03.subjects_id IN (${subjectsId}) ",
//            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
//            "AND t03.year_class_id in(${yearClassIdStr}) ",
//            "</when>",
//            "<when test='yearClassIdStr==null or yearClassIdStr==&apos;&apos; '>",
//            "AND t03.year_class_id &lt; 13 ",
//            "</when>",
            "<when test='include!=null and include!=&apos;&apos; and isIncludeFirstCourse == 0'>",
            "<when test='include == 0'>",
            "and t04.id IS NULL  ",
            "</when>",
            "<when test='include == 1'>",
            "and t04.id IS NOT NULL  ",
            "</when>",
            "</when>",

            "<when test='isBeforQuarter == 0 and readingType == 1'>",
            "AND t02.reading_status IN (1,5) ",
            "</when>",
            "<when test='isBeforQuarter == 1 and readingType == 1'>",
            "AND t02.reading_status IN (1,5)",
            "</when>",
            "<when test='readingType == 2'>",
            "AND ((t02.reading_status IN (1,5)) or (t02.reading_status in(3,4) and t02.use_course_count > 0)) ",
            "</when>",
//            "<when test='schoolIdStr!=null and schoolIdStr!=&apos;&apos; and (type == 2 || type == 4)'>",
//            "AND t03.school_id in(${schoolIdStr}) ",
//            "</when>",
//            "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
//            "AND t03.teacher_id in(${teacherId}) ",
//            "</when>",
            "and(",
            "(",
            "t03.school_id IN (${schoolIdStr})",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos;'>",
            "AND t03.year_class_id IN (${yearClassIdStr})",
            "</when>",
            ")",
            "or",
            "(",
            "t03.school_id IN (${leadSchoolIds})",
            "and t03.year_class_id IN (${leadYearClassIds})",
            "and t03.teacher_id IN (${leadTeacherId})",
            ")",
            ")",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "AND t02.class_type_id_new IN (${classTypeId}) ",
            "</when>",
            "<when test='type ==3'>",
            "AND t03.teacher_id in(select admin_id from xmy_erp_db.role_admin where role_id = 1568160887369994242) ",
            "</when>",
            "<when test='trackId!=null and trackId!=&apos;&apos; and type ==1'>",
            "AND t03.teacher_id in(select sourse_id from xmy_erp_db.track_detail where deleted = 0 and track_id =#{trackId}) ",
            "</when>",
            "<when test='trackId!=null and trackId!=&apos;&apos; and type ==4'>",
            "AND t03.school_id in(select sourse_id from xmy_erp_db.track_detail where deleted = 0 and track_id =#{trackId}) ",
            "</when>",
            "<when test='name!=null and name!=&apos;&apos; '>",
            "AND staff.`name` LIKE '%${name}%' ",
            "</when>",
            "GROUP BY student_id",
            "</when>",
            ") AS t01",

            "<when test='isIncludeFirstCourse == 1'>",
            "left JOIN record_course_with01 as t06 on t01.student_id = t06.student_id and t01.subjects_id = t06.subjects_id",
            "</when>",

            "LEFT JOIN ( SELECT * FROM edu_task WHERE deleted = 0 and task_category_id = ${taskCategoryId} and subjects_id IN (${subjectsId}) and task_course_num BETWEEN ${lessonNumStart} and ${lessonNum} ) AS t02 ON t01.year_part = t02.year_part ",
            "AND t01.quarter_num = t02.quarter_num ",
            "AND t01.subjects_id = t02.subjects_id ",
            "AND t01.class_type_id = t02.class_type_id",
            "AND t01.year_class_id = t02.year_class_id",
            "<when test= 'inType == 2'>",
            "inner",
            "</when>",
            "<when test= 'inType != 2'>",
            "LEFT",
            "</when>",
            "JOIN (",
            "SELECT",
            "student_id,",
            "add_date,",
            "lesson_num_finish,",
            "year_class_id,",
            "course_version_id,",
            "class_type_id,",
            "year_part,",
            "quarter_num,",
            "IFNULL( lesson_num, 0 ) AS lesson_num,",
            "right_num,",
            "is_last,",
            "is_first,",
            "amend_num, ",
            "pass_rade,",
            "brush_count,",
            "lowest_shutnum",
            "FROM",
            "cha_plan ",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND quarter_num = ${quarterNum} ",
            "AND task_category_id = ${taskCategoryId} ",
            "and deleted = 0",
            ") AS t03 ON t01.year_part = t03.year_part ",
            "AND t01.quarter_num = t03.quarter_num ",
            "AND t01.student_id = t03.student_id ",
            "AND t02.year_class_id = t03.year_class_id",
            "AND t02.course_version_id = t03.course_version_id",
            "AND t02.class_type_id = t03.class_type_id ",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and t01.subjects_id IN (${subjectsId})",
            "</when>",
            "AND t02.task_course_num = t03.lesson_num",
            "<when test='radeType!=null and radeType == 1 '>",
            "<when test='isAchieve!=null and isAchieve!=&apos;&apos; and isAchieve == 0'>",
            "and t03.is_last = 1",
            "</when>",
            "<when test='isAchieve!=null and isAchieve!=&apos;&apos; and isAchieve == 1'>",
            "and t03.is_first = 1",
            "</when>",
            "</when>",
            "<when test='radeType!=null and (radeType == 2 or radeType == 3) '>",
            "and t03.is_first = 1",
            "</when>",

            "LEFT JOIN ( ",
            "SELECT",
            "id,",
            "student_id,",
            "add_date,",
            "lesson_num_finish,",
            "year_class_id,",
            "course_version_id,",
            "class_type_id,",
            "year_part,",
            "quarter_num,",
            "IFNULL( lesson_num, 0 ) AS lesson_num,",
            "right_num,",
            "is_last,",
            "is_first,",
            "amend_num,",
            "pass_rade,",
            "brush_count,",
            "lowest_shutnum",
            "FROM",
            "cha_plan",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND quarter_num = ${quarterNum} ",
            "AND task_category_id = ${taskCategoryId} ",
            "AND deleted = 0",
            ") AS t04 ON t04.year_part = t03.year_part ",
            "AND t04.quarter_num = t03.quarter_num ",
            "AND t04.student_id = t03.student_id ",
            "AND t04.year_class_id = t03.year_class_id ",
            "AND t04.course_version_id = t03.course_version_id ",
            "AND t04.class_type_id = t03.class_type_id ",
            "AND t04.lesson_num = t03.lesson_num ",
            "and t04.is_last = 1 ",
            "and t04.is_first = 0 ",

            "where 1=1",
            "<when test='include!=null and include!=&apos;&apos; and isIncludeFirstCourse == 1'>",
                "<when test='include == 0'>",
                "and t06.id is not null",
                "</when>",
                "<when test='include == 1'>",
                "and t06.id is null",
                "</when>",
            "</when>",
            ") AS t ",
            "GROUP BY student_id ",
            "<if test= 'isYearClass == 1'>",
            ",year_class_id",
            "</if>",
            "<when test='type == 6'>",
            ") AS t02 ON t01.school_id = t02.school_id ",
            "</when>",
            "<when test='type != 6'>",
            ") AS t02 ",
            "</when>",
            "where 1=1",
//            "<when test='schoolIdStr!=null and schoolIdStr!=&apos;&apos; and (type == 2)'>",
//            "and school_id in(${schoolIdStr})",
//            "</when>",
//            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
//            "and year_class_id in(${yearClassIdStr})",
//            "</when>",

            "and(",
            "(",
            "school_id IN (${schoolIdStr})",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos;'>",
            "AND year_class_id IN (${yearClassIdStr})",
            "</when>",
            ")",
            "or",
            "(",
            "school_id IN (${leadSchoolIds})",
            "and year_class_id IN (${leadYearClassIds})",
            "and teacher_id IN (${leadTeacherId})",
            ")",
            ")",

            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "<when test='type ==3'>",
            "  and teacher_id in(select admin_id from xmy_erp_db.role_admin where role_id = 1568160887369994242)",
            "</when>",
            "<when test='trackId!=null and trackId!=&apos;&apos; and type ==1'>",
            "  and teacher_id in(select sourse_id from xmy_erp_db.track_detail where deleted = 0 and track_id =#{trackId})",
            "</when>",
            "<when test='trackId!=null and trackId!=&apos;&apos; and type ==4'>",
            "  and school_id in(select sourse_id from xmy_erp_db.track_detail where deleted = 0 and track_id =#{trackId})",
            "</when>",
            "GROUP BY ",
            "<if test= 'isYearClass == 1'>",
            "year_class_id,",
            "</if>",
            "<when test='type == 1 or type == 3'>",
            "teacher_id",
            "</when>",
            "<when test='type == 2'>",
            "school_id,teacher_id",
            "</when>",
            "<when test='type == 4 or type == 6'>",
            "school_id",
            "</when>",
            "<when test='listState == 1'>",
            ",grade_id",
            "</when>",
            "<if test= 'isYearClass == 1'>",
//                        "HAVING year_class_id IS NOT NULL",
            "</if>",
            "</script>"})
    public List<ChaPlan> getPassedBrushiDate(@Param("yearPart") String yearPart,
                                         @Param("quarterNum") String quarterNum,
                                         @Param("schoolIdStr") String schoolIdStr,
                                         @Param("yearClassIdStr") String yearClassIdStr,
                                         @Param("type") String type,
                                         @Param("lessonNumStart") String lessonNumStart,
                                         @Param("lessonNum") String lessonNum,
                                         @Param("classTypeId") String classTypeId,
                                         @Param("readingType") String readingType,
                                         @Param("lessonNow") String lessonNow,
                                         @Param("isAll") String isAll,
                                         @Param("passDate") String passDate,
                                         @Param("passDateStart") String passDateStart,
                                         @Param("passDateEnd") String passDateEnd,
                                         @Param("subjectsId") String subjectsId,
                                         @Param("isBeforQuarter") String isBeforQuarter,
                                         @Param("readingStatusStr") String readingStatusStr,
                                         @Param("rightNumStartDate") String rightNumStartDate,
                                         @Param("rightNumEndDate") String rightNumEndDate,
                                         @Param("trackId") String trackId,
                                         @Param("isYearClass") Integer isYearClass,
                                         @Param("radeType") String radeType,
                                         @Param("listState") String listState,
                                         @Param("teacherId") String teacherId,
                                         @Param("name") String name,
                                         @Param("include") String include,
                                         @Param("inType") String inType,
                                         @Param("taskCategoryId") Integer taskCategoryId,
                                         @Param("isAchieve") String isAchieve,
                                         @Param("moldType") String moldType, // 1、正常通关率 2、到勤通关率
                                         @Param("courseSchedulingDetailName") String courseSchedulingDetailName,
                                         @Param("schoolDateStart") String schoolDateStart,
                                         @Param("schoolDateEnd") String schoolDateEnd,
                                         @Param("examSchedulingtType") String examSchedulingtType,
                                         @Param("leadSchoolIds") String leadSchoolIds,
                                         @Param("leadSubjectsIds") String leadSubjectsIds,
                                         @Param("leadYearClassIds") String leadYearClassIds,
                                         @Param("leadTeacherId") Long leadTeacherId,
                                         @Param("isIncludeFirstCourse") String isIncludeFirstCourse

    );


    @Select({"<script>",
            "WITH tb_school_time_01 AS (",
            "SELECT *,",
            "MAX( CASE WHEN subjects_id = 1 THEN school_time END ) AS en_school_time,",
            "MAX( CASE WHEN subjects_id = 2 THEN school_time END ) AS ma_school_time,",
            "MAX( CASE WHEN subjects_id = 3 THEN school_time END ) AS ph_school_time ",
            "FROM (",
            "SELECT *, ",
            "GROUP_CONCAT( time_start_end ORDER BY t.week_dates ) AS school_time ",
            "FROM (",
            "SELECT t1.id,t1.year_part,t1.quarter_num,t1.student_id,t1.subjects_id,t2.week_dates,",
            "CONCAT(getWeekdayName ( t2.week_dates ), '', t2.time_start, ' - ', t2.time_end ) AS time_start_end ",
            "FROM ",
            "xmy_erp_db.student_grade AS t1 ",
            "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id ",
            "WHERE ",
            "t1.year_part = ${yearPart} ",
            "AND t1.quarter_num = ${quarterNum} ",
            "AND t1.lesson_type &lt;&gt; 1",
            "AND t1.deleted = 0 ",
            "AND t1.`status` = 1 ",
            "<if test= 'readingType == 1'>",
                "<if test= 'isBeforQuarter == 0'>",
                    "AND t1.reading_status = 1 ",
                "</if>",
                "<if test= 'isBeforQuarter == 1'>",
                    "AND t1.reading_status IN (1,3,4,5,6 ) ",
                "</if>",
            "</if>",
            "<if test= 'readingType == 2'>",
                "AND t1.reading_status IN (1,3,4,5,6 ) ",
            "</if>",
            "GROUP BY t1.grade_id,t1.student_id,t1.subjects_id ",
            ") AS t ",
            "GROUP BY student_id,subjects_id ",
            ") AS t ",
            "GROUP BY student_id",
            ")",
            "<when test='isIncludeFirstCourse == 1'>",
            ", record_course_with01 as (select id,year_part,`quarter`,subjects_id,student_id from xmy_erp_db.record_course where year_part = ${yearPart} and `quarter` = ${quarterNum} and lesson_num =1 and course_type =1 and lesson_type=1 and deleted =0 GROUP BY student_id)",
            "</when>",
            "SELECT",
                    "*,if(brush_count_temp = 0,1,brush_count_temp) as brush_count  ",
                    "<when test='listState != 1 and listState != 2'>",
                        ",pass_date_time1 AS pass_date_time ",
                    "</when>",
                    "<when test='listState == 1 or listState == 2'>",
                        ",MAX( pass_date_time1 ) AS pass_date_time ",
                    "</when>",
                    "<when test='listState == 2'>",// 正确率学员详情，为了不影响其他的合并课次数据，所以改成了2，为1的不适用于正确率
                        ",GROUP_CONCAT( lesson_num ) AS LessonNumNot,",
                        "SUM(lowest_shutnum) AS lowestShutnumAll,",
                        "SUM(right_num) AS rightNumAll,",
                        "SUM(amend_num) AS amendNumAll",
                    "</when>",
                    "FROM",
                    "(",
                    "SELECT",
                      "t01.id,",
                      "t01.subjects_id,",
                      "t01.school_id,",
                      "t01.year_part,",
                      "t01.quarter_num,",
                      "t02.course_version_id,",
                      "t01.grade_id,",
                      "t01.teacher_id,",
                      "t01.class_type_id,",
                      "t01.year_class_id,",
                      "t01.student_id,",
                      "t01.linkman_phone,",
                      "t02.task_course_num AS lesson_num,",
                      "t02.not_brush,",
                      "t03.is_first,",
                      "t03.is_last,",
                      "t07.en_school_time,",
                      "t07.ma_school_time,",
                      "t07.ph_school_time,",
                      "t04.id AS again_brush_id, ",
                      "IFNULL( t03.brush_count,0) as brush_count_temp,",
                      "IFNULL( t03.brush_count &gt; 0 AND t03.lowest_shutnum &lt;&gt; 0 AND t03.lowest_shutnum IS NOT NULL, 1) AS yet_finish_count, ",// 已完成
                      "IFNULL( t03.is_first = 1 AND (( t03.right_num / t03.lowest_shutnum )* 100 &lt; t03.pass_rade ) AND t03.lowest_shutnum &lt;&gt; 0 AND t03.lowest_shutnum IS NOT NULL AND t04.id IS NOT NULL , 1 ) AS yet_rebrush_count,",// 已复刷
                      "IFNULL( t03.pass_rade,t02.pass_rade) as pass_rade, ",
                      "( CASE WHEN t03.right_num IS NOT NULL AND t03.pass_rade &gt; 0 and (t03.right_num + t03.amend_num ) &gt;= t03.lowest_shutnum AND ( t03.right_num / t03.lowest_shutnum )* 100 &gt;= t03.pass_rade THEN t03.lowest_shutnum ELSE t02.lowest_shutnum END ) AS lowest_shutnum,",
                      "IFNULL( t03.right_num, 0 ) AS right_num,",
                      "IFNULL( t03.amend_num, 0 ) AS amend_num,",
                      "t03.add_date, ",
                      "t05.in_school_time, ",
                      "t03.pass_date_time as pass_date_time1",
                    "FROM",
                      "(",
                    "<when test= 'moldType == 1'>",
                      "SELECT",
                        "t1.*,",
                        "t1.class_type_id_new AS class_type_id,",
                        "t2.teacher_id,",
                        "t5.linkman_phone",
                      "FROM",
                        "xmy_erp_db.student_grade AS t1",
                        "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id ",
                        "INNER JOIN per_student_account AS t3 ON t1.student_id = t3.student_id",
                        "INNER JOIN xmy_erp_db.student AS t5 ON t1.student_id = t5.id ",
                         "LEFT JOIN xmy_erp_db.rade_exclude_student AS t4 ON t4.classify_id = 0 AND t4.deleted = 0 AND t4.type = 2 AND t1.student_id = t4.student_id AND t1.year_part = t4.year_part AND t1.quarter_num = t4.quarter_num AND ( FIND_IN_SET( t1.subjects_id, t4.subjects_ids ) OR t4.subjects_ids IS NULL ) AND ( FIND_IN_SET( t1.school_id, t4.school_ids ) OR t4.school_ids IS NULL ) ",
                        "WHERE",
                        "t1.year_part = ${yearPart} ",
                        "AND t1.quarter_num = ${quarterNum}",
                        "AND t1.lesson_type = 1",
                        "AND t1.deleted = 0 ",
                        "AND t1.subjects_id = ${subjectsId} ",
                        "AND t1.is_last = 1 ",
                        "<when test='include!=null and include!=&apos;&apos; and isIncludeFirstCourse == 0'>",
                            "<when test='include == 0'>",
                                "and t4.id is null ",
                            "</when>",
                            "<when test='include == 1'>",
                                "and t4.id is not null ",
                            "</when>",
                        "</when>",
                        "<when test='isBeforQuarter == 0 and readingType == 1'>",
                            "AND t1.reading_status IN (1,5) ",
                        "</when>",
                        "<when test='isBeforQuarter == 1 and readingType == 1'>",
                            "AND t1.reading_status IN (1,5)",
                        "</when>",
                        "<when test='readingType == 2'>",
                            "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and use_course_count > 0)) ",
                        "</when>",
                        "AND t1.STATUS &lt;&gt; 3 ",
                        "AND t1.deleted = 0 ",
                        "<when test='gradeId!=null and gradeId!=&apos;&apos;'>",
                            "and t1.grade_id = ${gradeId}",
                        "</when>",
                        "<when test='studentName!=null and studentName!=&apos;&apos;'>",
                            "AND t1.student_id IN (SELECT id FROM xmy_erp_db.student WHERE `name` LIKE '%${studentName}%' AND `status` = 1 AND deleted = 0)",
                        "</when>",
//                        "<when test='schoolIdStr!=null and schoolIdStr!=&apos;&apos; and (type == 2 || type==4)'>",
//                        "and t1.school_id in(${schoolIdStr})",
//                        "</when>",
//                        "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
//                        "and t2.year_class_id in(${yearClassIdStr})",
//                        "</when>",
//                        "<when test='yearClassIdStr==null or yearClassIdStr==&apos;&apos; '>",
//                        "and t2.year_class_id &lt; 13",
//                        "</when>",
                        "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
                        "and t1.class_type_id_new IN (${classTypeId})",
                        "</when>",
//                        "<when test='teacherId!=null and teacherId!=&apos;&apos; and type != 4'>",
//                        "  and t2.teacher_id = ${teacherId}",
//                        "</when>",
                        "and(",
                        "(",
                        "t1.school_id IN (${schoolIdStr})",
                        "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos;'>",
                        "AND t2.year_class_id IN (${yearClassIdStr})",
                        "</when>",
                        "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
                        "AND t2.teacher_id = ${teacherId}",
                        "</when>",
                        ")",
                        "or",
                        "(",
                        "t1.school_id IN (${leadSchoolIds})",
                        "and t2.year_class_id IN (${leadYearClassIds})",
                        "and t2.teacher_id IN (${leadTeacherId})",
                        ")",
                        ")",

                      "GROUP BY",
                        "student_id ",
                    "</when>",

                        "<when test= 'moldType == 2'>",
                            "SELECT",
                            "t02.*, ",
                            "t02.class_type_id_new AS class_type_id,",
                            "t03.teacher_id,",
                            "t03.`name` AS grade_name,",
                            "staff.`name` AS teacher_name, ",
                            "t06.linkman_phone ",
                            "FROM",
                            "(",
                                "SELECT",
                                "t1.school_id,",
                                "t1.old_teacher_id AS teacher_id,",
                                "t1.student_id,",
                                "t1.`status`,",
                                "t1.reach_type,",
                                "t1.old_grade_id AS grade_id,",
                                "t1.subjects_id,",
                                "t1.year_class_id,",
                                "t1.time_start,",
                                "t1.time_end,",
                                "t1.course_type, ",
                                "t1.lesson_num,",
                                "t1.school_date,",
                                "t10.year_part,",
                                "t10.quarter_num ",
                                "FROM",
                                "xmy_erp_db.record_course AS t1 ",
                                "INNER JOIN xmy_erp_db.grade AS t10 ON t1.grade_id = t10.id AND t10.is_rebrush = 0 ",
                                "WHERE",
                                "t1.deleted = 0 ",
                                "AND t1.year_part = ${yearPart} ",
                                "AND t1.`quarter` = ${quarterNum} ",
                                "AND t1.`lesson_type` = 3 ",
                                "AND t1.old_teacher_id IS NOT NULL ",
                                "AND ((t1.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ) OR ( t1.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' AND t1.course_type = 7 )) ",

                                "UNION ALL ",

                                "SELECT",
                                "t4.school_id,",
                                "t4.teacher_id,",
                                "t1.student_id,",
                                "t5.`status`,",
                                "t5.reach_type,",
                                "t6.grade_id,",
                                "t2.subjects_id,",
                                "t4.year_class_id,",
                                "t2.time_start,",
                                "t2.time_end,",
                                "1 AS course_type, ",
                                "t2.lesson_num,",
                                "t2.school_date, ",
                                "t10.year_part,",
                                "t10.quarter_num ",
                                "FROM",
                                "xmy_erp_db.${courseSchedulingDetailName} AS t2",
                                "INNER JOIN xmy_erp_db.grade AS t10 ON t2.grade_id = t10.id AND t10.is_rebrush = 0 ",
                                "INNER JOIN xmy_erp_db.student_grade AS t1 ON t2.year_part = t1.year_part ",
                                "AND t2.`quarter` = t1.quarter_num ",
                                "AND t2.deleted = t1.deleted ",
                                "AND t2.grade_id = t1.grade_id ",
                                "AND t2.lesson_type = t1.lesson_type ",
                                "<when test='isBeforQuarter == 0 and readingType == 1'>",
                                    "AND t1.reading_status IN (1,5) ",
                                "</when>",
                                "<when test='isBeforQuarter == 1 and readingType == 1'>",
                                    "AND t1.reading_status IN (1,5)",
                                "</when>",
                                "<when test='readingType == 2'>",
                                    "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and t1.use_course_count > 0)) ",
                                "</when>",
                                "AND t1.`status` = 1",
                                "INNER JOIN xmy_erp_db.student_grade AS t6 ON t6.year_part = t1.year_part ",
                                "AND t6.`quarter_num` = t1.quarter_num ",
                                "AND t6.deleted = t1.deleted ",
                                "AND t6.subjects_id = t1.subjects_id ",
                                "AND t6.`student_id` = t1.student_id ",
                                "AND t6.lesson_type = 1 ",
                                "<when test='isBeforQuarter == 0 and readingType == 1'>",
                                    "AND t6.reading_status IN (1,5) ",
                                "</when>",
                                "<when test='isBeforQuarter == 1 and readingType == 1'>",
                                    "AND t6.reading_status IN (1,5)",
                                "</when>",
                                "<when test='readingType == 2'>",
                                    "AND ((t6.reading_status IN (1,5)) or (t6.reading_status in(3,4) and t6.use_course_count > 0)) ",
                                "</when>",
                                "AND t6.`status` = 1",
                                "and t2.end_date_time &gt;= t6.created_at",
                                "LEFT JOIN xmy_erp_db.repair_course AS t3 ON t3.out_scheduling_detail_id = t2.id AND t3.deleted = 0",
                                "AND t3.student_id = t1.student_id",
                                "LEFT JOIN xmy_erp_db.grade AS t4 ON t6.grade_id = t4.id",
                                "LEFT JOIN xmy_erp_db.record_course AS t5 ON t5.scheduling_detail_id = t2.id ",
                                "AND t5.student_id = t1.student_id ",
                                "AND t5.deleted = 0 ",
                                "WHERE",
                                "t2.year_part = ${yearPart} ",
                                "AND t2.`quarter` = ${quarterNum} ",
                                "AND t2.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
                                "AND t2.lesson_type = 3 ",
                                "AND t2.deleted = 0 ",
                                "AND t2.`status` &lt;&gt; 2 ",
                                "AND t3.id IS NULL ",
                                "GROUP BY",
                                "t2.id,",
                                "t1.school_id,",
                                "t1.subjects_id,",
                                "t1.student_id,",
                                "t1.lesson_type ",
                            ") AS t01",
                            "INNER JOIN xmy_erp_db.student_grade AS t02 ON t01.student_id = t02.student_id ",
                            "AND t01.subjects_id = t02.subjects_id ",
                            "AND t01.year_part = t02.year_part ",
                            "AND t01.quarter_num = t02.quarter_num ",
                            "AND t02.lesson_type = 1 ",
                            "AND t02.deleted = 0 ",
                            "AND t02.is_last = 1 ",
                            "INNER JOIN xmy_erp_db.grade AS t03 ON t02.grade_id = t03.id ",
                            "INNER JOIN xmy_erp_db.staff ON staff.id = t03.teacher_id ",
                            "LEFT JOIN xmy_erp_db.rade_exclude_student AS t04 ON t04.classify_id = 0 ",
                            "AND t04.deleted = 0 ",
                            "AND t04.type = 2 ",
                            "AND t02.student_id = t04.student_id ",
                            "AND t02.year_part = t04.year_part ",
                            "AND t02.quarter_num = t04.quarter_num ",
                            "AND ( FIND_IN_SET( t02.subjects_id, t04.subjects_ids ) OR t04.subjects_ids IS NULL ) ",
                            "AND ( FIND_IN_SET( t02.school_id, t04.school_ids ) OR t04.school_ids IS NULL ) ",
                            "INNER JOIN per_student_account AS t05 ON t05.student_id = t01.student_id ",
                            "INNER JOIN xmy_erp_db.student AS t06 ON t01.student_id = t06.id ",
                            "LEFT JOIN xmy_erp_db.cha_study_plan AS csp ON t01.student_id = csp.student_id ",
                            "AND csp.subjects_id = t01.subjects_id ",
                            "AND csp.lesson_type = 3 ",
                            "AND csp.`status` = 1 ",
                            "AND csp.year_part = ${yearPart}",
                            "AND csp.quarter_num = ${quarterNum} ",
                            "AND school_date BETWEEN csp.start_task_date AND csp.end_task_date ",
                            "AND DATE(csp.created_at) &lt; school_date ",
                            "WHERE ",
//                            "((t01.`status` = 1 AND course_type &lt;&gt; 7 ) OR ( course_type = 7 )) ",
                            "t01.`status` = 1 ",
                            "AND t02.`status` &lt;&gt; 3 ",
                            "AND t03.year_part = ${yearPart} ",
                            "AND t03.quarter_num = ${quarterNum} ",
                            "AND t03.lesson_type = 1 ",
                            "AND csp.student_id IS NULL",
                            "AND t03.subjects_id IN (${subjectsId}) ",
//                            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
//                                "AND t03.year_class_id in(${yearClassIdStr}) ",
//                            "</when>",
//                            "<when test='yearClassIdStr==null or yearClassIdStr==&apos;&apos; '>",
//                                "AND t03.year_class_id &lt; 13 ",
//                            "</when>",
                            "<when test='include!=null and include!=&apos;&apos; and isIncludeFirstCourse == 0'>",
                                "<when test='include == 0'>",
                                    "and t04.id IS NULL  ",
                                "</when>",
                                "<when test='include == 1'>",
                                    "and t04.id IS NOT NULL  ",
                                "</when>",
                            "</when>",
                            "<when test='isBeforQuarter == 0 and readingType == 1'>",
                                "AND t02.reading_status IN (1,5) ",
                            "</when>",
                            "<when test='isBeforQuarter == 1 and readingType == 1'>",
                            "AND t02.reading_status IN (1,5)",
                                "</when>",
                            "<when test='readingType == 2'>",
                                "AND ((t02.reading_status IN (1,5)) or (t02.reading_status in(3,4) and t02.use_course_count > 0)) ",
                            "</when>",
//                            "<when test='schoolIdStr!=null and schoolIdStr!=&apos;&apos; and (type == 2 || type == 4)'>",
//                                "AND t03.school_id in(${schoolIdStr}) ",
//                            "</when>",
//                            "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
//                                "AND t03.teacher_id in(${teacherId}) ",
//                            "</when>",
                            "and(",
                            "(",
                            "t03.school_id IN (${schoolIdStr})",
                            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos;'>",
                            "AND t03.year_class_id IN (${yearClassIdStr})",
                            "</when>",
                            "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
                            "AND t03.teacher_id = ${teacherId}",
                            "</when>",
                            ")",
                            "or",
                            "(",
                            "t03.school_id IN (${leadSchoolIds})",
                            "and t03.year_class_id IN (${leadYearClassIds})",
                            "and t03.teacher_id IN (${leadTeacherId})",
                            ")",
                            ")",

                            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
                                "AND t02.class_type_id_new IN (${classTypeId}) ",
                            "</when>",
                            "GROUP BY student_id",
                        "</when>",

                    ") AS t01",
                        "<when test='isIncludeFirstCourse == 1'>",
                        "LEFT JOIN record_course_with01 as t06 on t01.student_id = t06.student_id and t01.subjects_id = t06.subjects_id",
                        "</when>",
                      "INNER JOIN ( SELECT * FROM edu_task WHERE deleted = 0 and task_category_id = ${taskCategoryId} and subjects_id = ${subjectsId} and task_course_num BETWEEN ${lessonNumStart} and ${lessonNum}) AS t02 ON t01.year_part = t02.year_part ",
                      "AND t01.quarter_num = t02.quarter_num ",
                      "AND t01.subjects_id = t02.subjects_id ",
                      "AND t01.class_type_id = t02.class_type_id",
                      "AND t01.year_class_id = t02.year_class_id",
                        "<when test='(inType != 2)'>",
                            "LEFT ",
                        "</when>",
                        "<when test='(inType == 2)'>",
                            "INNER",
                        "</when>",
                      "JOIN (SELECT",
                        "student_id,",
                        "add_date,",
                        "lesson_num_finish,",
                        "year_class_id,",
                        "course_version_id,",
                        "class_type_id,",
                        "year_part,",
                        "quarter_num,",
                        "IFNULL( lesson_num, 0 ) AS lesson_num,",
                        "right_num,",
                        "is_last,",
                        "is_first,",
                        "amend_num, ",
                        "lowest_shutnum, ",
                        "brush_count, ",
                        "pass_rade,",
                        "pass_date_time ",
                      "FROM",
                        "cha_plan ",
                      "WHERE",
                        "year_part = ${yearPart} ",
                        "AND quarter_num = ${quarterNum}",
                        "AND task_category_id = ${taskCategoryId}",
                        "and deleted = 0",
                        "<when test='rightNumStartDate != &apos;&apos; and rightNumEndDate != &apos;&apos;'>",
                            "AND add_date BETWEEN '${rightNumStartDate}' AND '${rightNumEndDate}' ",
                            "AND right_num &gt; 0 ",
                        "</when>",
                      ") AS t03 ON t01.year_part = t03.year_part ",
                      "AND t01.quarter_num = t03.quarter_num ",
                      "AND t01.student_id = t03.student_id ",
                      "AND t02.year_class_id = t03.year_class_id ",
                      "AND t02.class_type_id = t03.class_type_id ",
                      "AND t02.course_version_id = t03.course_version_id",
                        "<when test='courseVersionId!=null and courseVersionId!=&apos;&apos;'>",
                            "and t02.course_version_id = ${courseVersionId}",
                        "</when>",
                        "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
                            "and t01.subjects_id = ${subjectsId}",
                        "</when>",
                        //"<when test='isAll == 0'>",
                        //    "AND t02.task_course_num = t03.lesson_num",
                        //    "AND t02.task_course_num = t03.lesson_num_finish",
                        //"</when>",
                        //"<when test='isAll == 1'>",
                        //    "AND t02.task_course_num = t03.lesson_num",
                        //    "and t03.is_last = 1",
                        //"</when>",
                        "AND t02.task_course_num = t03.lesson_num",
                        "<when test='radeType!=null and radeType == 1 '>",
                            "<when test='passType!=null and passType!=&apos;&apos; and passType != 9 and passType != 10 and passType != 11 and passType != 12'>",
                                "and t03.is_last = 1",
                            "</when>",
                            "<when test='passType!=null and passType!=&apos;&apos; and (passType == 9 or passType == 10 or passType == 11 or passType == 12 )'>",
                                "and t03.is_first = 1",
                            "</when>",
                        "</when>",
                        "<when test='radeType!=null and (radeType == 2 or radeType == 3) '>",
                            "and t03.is_first = 1",
                        "</when>",

                        "LEFT JOIN ( ",
                        "SELECT",
                        "id,",
                        "student_id,",
                        "add_date,",
                        "lesson_num_finish,",
                        "year_class_id,",
                        "course_version_id,",
                        "class_type_id,",
                        "year_part,",
                        "quarter_num,",
                        "IFNULL( lesson_num, 0 ) AS lesson_num,",
                        "right_num,",
                        "is_last,",
                        "is_first,",
                        "amend_num,",
                        "pass_rade,",
                        "brush_count,",
                        "lowest_shutnum",
                        "FROM",
                        "cha_plan",
                        "WHERE",
                        "year_part = ${yearPart} ",
                        "AND quarter_num = ${quarterNum} ",
                        "AND task_category_id = ${taskCategoryId} ",
                        "AND deleted = 0",
                        ") AS t04 ON t04.year_part = t03.year_part ",
                        "AND t04.quarter_num = t03.quarter_num ",
                        "AND t04.student_id = t03.student_id ",
                        "AND t04.year_class_id = t03.year_class_id ",
                        "AND t04.course_version_id = t03.course_version_id ",
                        "AND t04.class_type_id = t03.class_type_id ",
                        "AND t04.lesson_num = t03.lesson_num ",
                        "and t04.is_last = 1 ",
                        "and t04.is_first = 0 ",
//                        "where 1=1",
//                        "<when test='include!=null and include!=&apos;&apos; and isIncludeFirstCourse = 1'>",
//                            "<when test='include == 0'>",
//                            "and t05.id is not null",
//                            "</when>",
//                            "<when test='include == 1'>",
//                            "and t05.id is null",
//                            "</when>",
//                        "</when>",
                        // 计算在校时长：
                        // 正常情况：签退时间-签到时间 = 在校时间
                        // 签到时间为空：如果当前时间和add_date是同一天，并且当前时间没有超过23点，那么使用当前时间减去签到时间，计算在校时间
                        // 签到时间为空：如果当前时间和add_date是同一天，并且当前时间超过23点，那么显示“无效”
                        // 签到时间为空：如果当前时间和add_date不是同一天，那么显示“无效”
                        // 多选日期，在校时长相加，并且不计算无效时间数据
                        "LEFT JOIN ( ",
                            "SELECT",
                            "student_id,subjects_id,IF(SUM(in_school_time) = 0, '无效', IFNULL(SUM(in_school_time), 0)) AS in_school_time ",
                            "FROM ",
                            "( ",
                                "SELECT t1.student_id,t1.subjects_id,t1.school_date,",
                                "CASE ",
                                "WHEN in_date_time IS NOT NULL AND out_date_time IS NOT NULL THEN TIMESTAMPDIFF( MINUTE, in_date_time, out_date_time ) ",
                                "WHEN in_date_time IS NOT NULL AND out_date_time IS NULL THEN ",
                                "CASE ",
                                "WHEN DATE ( add_date ) = CURDATE() AND HOUR (NOW()) &lt; 23 THEN TIMESTAMPDIFF( MINUTE, in_date_time, NOW()) ",
                                "WHEN DATE ( add_date ) = CURDATE() AND HOUR ( NOW()) &gt;= 23 THEN 0 ELSE 0 END ELSE 0 END AS in_school_time ",
                                "FROM",
                                "xmy_erp_db.record_course AS t1 ",
                                "LEFT JOIN xmy_erp_db.student_sign_in AS t2 ON t1.scheduling_detail_id = t2.scheduling_detail_id AND t1.student_id = t2.student_id AND t2.add_date = t1.school_date AND t2.subjects_id = t1.subjects_id",
                                "WHERE ",
                                "t1.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
                                "AND t1.lesson_type = 3",
                                "AND t1.subjects_id = ${subjectsId}",
                            ") AS student_sign_in ",
                            "GROUP BY ",
                            "student_id ",
                        ") t05 ON t05.student_id = t01.student_id AND t05.subjects_id = t01.subjects_id ",
                        "LEFT JOIN tb_school_time_01 AS t07 ON t01.year_part = t07.year_part AND t01.quarter_num = t07.quarter_num AND t01.student_id = t07.student_id ",


                            "where 1=1",
                            "<when test='include!=null and include!=&apos;&apos; and isIncludeFirstCourse == 1'>",
                            "<when test='include == 0'>",
                            "and t06.id is not null",
                            "</when>",
                            "<when test='include == 1'>",
                            "and t06.id is null",
                            "</when>",
                        "</when>",
//                        "GROUP BY t01.student_id",
                    ") AS t",
                    "where 1=1",
                    "<when test='passType!=null and passType!=&apos;&apos; and passType == 2'>",// 已通关
                      " AND ((( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR ( brush_count_temp &gt;= 2 AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR ( not_brush = 1 AND ( right_num + amend_num ) &gt;= lowest_shutnum )) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
//                    " AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND ( right_num + amend_num &gt;= lowest_shutnum ) AND lowest_shutnum &lt;&gt; 0 and lowest_shutnum IS NOT NULL",
//                    " AND ( right_num + amend_num ) &gt;= lowest_shutnum AND lowest_shutnum &lt;&gt; 0",
//                    " AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND lowest_shutnum &lt;&gt; 0",
                    "</when>",
                    "<when test='passType!=null and passType!=&apos;&apos; and passType == 3'>",// 未通关
                      " AND ((not_brush = 0 and brush_count_temp &lt;= 1 AND (right_num / lowest_shutnum )* 100 &lt; pass_rade ) OR ( not_brush = 0 and brush_count_temp &gt;= 2 AND ( right_num + amend_num ) &lt; lowest_shutnum ) OR (( right_num / lowest_shutnum )* 100 &gt;= pass_rade  AND ( right_num + amend_num ) &lt; lowest_shutnum ) OR ( not_brush = 1 AND ( right_num + amend_num ) &lt; lowest_shutnum )) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
//                    " AND ((( right_num / lowest_shutnum )* 100 &lt; pass_rade) OR ((right_num / lowest_shutnum * 100 &gt;= pass_rade) AND (right_num + amend_num &lt; lowest_shutnum))) AND lowest_shutnum &lt;&gt; 0 ",
//                    " AND (  ( right_num + amend_num ) &lt; lowest_shutnum and lowest_shutnum &lt;&gt; 0)",
//                    " AND (  ( right_num / lowest_shutnum )* 100 &lt; pass_rade and lowest_shutnum &lt;&gt; 0)",
                    "</when>",
                    "<when test='passType!=null and passType!=&apos;&apos; and passType == 4'>",// 今日已通关
                      " AND ((( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR ( brush_count_temp &gt;= 2 AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR (not_brush = 1 and ( right_num + amend_num ) &gt;= lowest_shutnum)) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
//                    " AND ( right_num + amend_num ) &gt;= lowest_shutnum AND lowest_shutnum &lt;&gt; 0",
//                    " AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND lowest_shutnum &lt;&gt; 0 ",
                    "and add_date BETWEEN '${passDateStart}' AND '${passDateEnd}'",
                    "</when>",
                    "<when test='passType!=null and passType!=&apos;&apos; and passType == 5'>",// 未刷（未完成）
                        "and brush_count_temp = 0 AND (right_num =0 and amend_num=0  and lowest_shutnum is not null)",
                    "</when>",
                    "<when test='passType!=null and passType!=&apos;&apos; and passType == 6'>", // 通关率——>需复刷
//                        "AND brush_count_temp &gt;= 1 AND brush_count_temp &lt;= 2 AND (right_num + amend_num) &lt; lowest_shutnum AND lowest_shutnum &lt;&gt; 0",
                        "and not_brush = 0 AND brush_count_temp &gt;= 1 AND (brush_count_temp &lt; 2 OR (right_num + amend_num &lt; lowest_shutnum)) AND ((( right_num / lowest_shutnum )* 100 &lt; pass_rade) OR ((right_num / lowest_shutnum * 100 &gt;= pass_rade) AND (right_num + amend_num &lt; lowest_shutnum))) AND lowest_shutnum &lt;&gt; 0",
//                        "and brush_count_temp &gt;= 1 AND ((( right_num / lowest_shutnum )* 100 &lt; pass_rade ) and lowest_shutnum &lt;&gt; 0)",
                    "</when>",
                    "<when test='passType!=null and passType!=&apos;&apos; and passType == 7'>",// 第一种已完成详情（录了就算已完成）
                        "AND brush_count_temp &gt; 0 AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL",
                    "</when>",
                    "<when test='passType!=null and passType!=&apos;&apos; and passType == 8'>",// 第一种根据日期已完成详情（录了就算已完成）
                        "AND brush_count_temp &gt; 0 AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL",
                        "and add_date BETWEEN '${passDateStart}' AND '${passDateEnd}'",
                    "</when>",
                    "<when test='passType!=null and passType!=&apos;&apos; and passType == 9'>",// 应复刷详情
                        "AND is_first = 1  ",
                        "AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade )",
                        "AND lowest_shutnum &lt;&gt; 0 ",
                        "AND lowest_shutnum IS NOT NULL ",
                    "</when>",
                    "<when test='passType!=null and passType!=&apos;&apos; and passType == 10'>",// 已复刷详情
                        "AND is_first = 1 ",
                        "AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade ) ",
                        "AND lowest_shutnum &lt;&gt; 0 ",
                        "AND lowest_shutnum IS NOT NULL ",
                        "AND again_brush_id IS NOT NULL ",
                    "</when>",
                    "<when test='passType!=null and passType!=&apos;&apos; and passType == 11'>",// 根据日期已复刷详情
                        "AND is_first = 1 ",
                        "AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade ) ",
                        "AND lowest_shutnum &lt;&gt; 0 ",
                        "AND lowest_shutnum IS NOT NULL ",
                        "AND again_brush_id IS NOT NULL ",
                        "and add_date BETWEEN '${passDateStart}' AND '${passDateEnd}'",
                    "</when>",
                    "<when test='passType!=null and passType!=&apos;&apos; and passType == 12'>",// 未复刷
                        "AND is_first = 1  ",
                        "AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade )",
                        "AND lowest_shutnum &lt;&gt; 0 ",
                        "AND lowest_shutnum IS NOT NULL ",
                        "AND again_brush_id IS NULL ",
                    "</when>",
                    "<when test='passType!=null and passType!=&apos;&apos; and passType == 13'>",// 应修正
                        "AND brush_count_temp &gt;= 1 AND ( right_num + amend_num ) &lt; lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
                    "</when>",
                    "<when test='passType!=null and passType!=&apos;&apos; and passType == 14'>",// 已完成（正确+修正>=应通关）
                        "AND brush_count_temp = 1 AND (right_num + amend_num) &gt;= lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
                    "</when>",
                    "<when test='passType!=null and passType!=&apos;&apos; and passType == 15'>",// 今日已完成（正确+修正>=应通关）
                        "AND brush_count_temp = 1 AND (right_num + amend_num) &gt;= lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
                        "AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
                    "</when>",
                    "<when test='passType!=null and passType!=&apos;&apos; and passType == 16'>",// 需修正（第一次需修正）
                        "AND brush_count_temp = 1 AND ( right_num + amend_num ) &lt; lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
                    "</when>",
                    "<when test='passType!=null and passType!=&apos;&apos; and passType == 17'>",// 复刷应通关
                        "AND (brush_count_temp &gt;= 1 AND (brush_count_temp &lt; 2 OR ( right_num + amend_num &lt; lowest_shutnum )) AND (((right_num / lowest_shutnum )* 100 &lt; pass_rade ) OR (( right_num / lowest_shutnum * 100 &gt;= pass_rade ) AND ( right_num + amend_num &lt; lowest_shutnum ))) OR brush_count_temp &gt;= 2 ) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
                    "</when>",
                    "<when test='passType!=null and passType!=&apos;&apos; and passType == 18'>",// 复刷已通关
                        "AND (( brush_count_temp &gt;= 2 AND (( right_num + amend_num ) &gt;= lowest_shutnum AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade ))) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL",
                    "</when>",
                    "<when test='passType!=null and passType!=&apos;&apos; and passType == 19'>",// 复刷未通关
                        "AND ( brush_count_temp &gt;= 1 AND (( right_num + amend_num ) &lt; lowest_shutnum OR ( right_num / lowest_shutnum )* 100 &lt; pass_rade )) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
                    "</when>",
                    "<when test='passType!=null and passType!=&apos;&apos; and passType == 20'>",// 复刷今日已通关
                        "AND (( brush_count_temp &gt;= 2 AND (( right_num + amend_num ) &gt;= lowest_shutnum AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade ))) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL",
                        "AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
                    "</when>",
                    "<when test='studentIdStr!=null and studentIdStr!=&apos;&apos; '>",
                        "AND student_id IN (${studentIdStr}) ",
                    "</when>",
                    "<when test='listState == 1 or listState == 2'>",
                        "GROUP BY student_id",
                    "</when>",
                    "ORDER BY pass_date_time IS NULL ASC,pass_date_time ASC,student_id,lesson_num ASC",
                    "</script>"})
    public IPage<ChaPlan> getPassRadeDetail(IPage<?> page,
                                            @Param("yearPart") String yearPart,
                                            @Param("quarterNum") String quarterNum,
                                            @Param("schoolIdStr") String schoolIdStr,
                                            @Param("teacherId") String teacherId,
                                            @Param("yearClassIdStr") String yearClassIdStr,
                                            @Param("type") String type,
                                            @Param("gradeId") String gradeId,
                                            @Param("lessonNumStart") String lessonNumStart,
                                            @Param("lessonNum") String lessonNum,
                                            @Param("classTypeId") String classTypeId,
                                            @Param("readingType") String readingType,
                                            @Param("passType") String passType,
                                            @Param("lessonNow") String lessonNow,
                                            @Param("isAll") String isAll,
                                            @Param("courseVersionId") Long courseVersionId,
                                            @Param("passDate") String passDate,
                                            @Param("passDateStart") String passDateStart,
                                            @Param("passDateEnd") String passDateEnd,
                                            @Param("subjectsId") Long subjectsId,
                                            @Param("isBeforQuarter") String isBeforQuarter,
                                            @Param("readingStatusStr") String readingStatusStr,
                                            @Param("rightNumStartDate") String rightNumStartDate,
                                            @Param("rightNumEndDate") String rightNumEndDate,
                                            @Param("studentName") String studentName,
                                            @Param("radeType") String radeType,
                                            @Param("listState") String listState,
                                            @Param("include") String include,
                                            @Param("inType") String inType,
                                            @Param("taskCategoryId") Integer taskCategoryId,
                                            @Param("courseSchedulingDetailName") String courseSchedulingDetailName,
                                            @Param("studentIdStr") String studentIdStr,
                                            @Param("moldType") String moldType,  // 1、正常通关率 2、到勤通关率
                                            @Param("leadSchoolIds") String leadSchoolIds,
                                            @Param("leadSubjectsIds") String leadSubjectsIds,
                                            @Param("leadYearClassIds") String leadYearClassIds,
                                            @Param("leadTeacherId") Long leadTeacherId,
                                            @Param("isIncludeFirstCourse") String isIncludeFirstCourse
    );

    /**
     * 已过刷题排班和未到刷题排班详情
     */
    @Select({"<script>",
            "WITH tb_school_time_01 AS (",
            "SELECT *,",
            "MAX( CASE WHEN subjects_id = 1 THEN school_time END ) AS en_school_time,",
            "MAX( CASE WHEN subjects_id = 2 THEN school_time END ) AS ma_school_time,",
            "MAX( CASE WHEN subjects_id = 3 THEN school_time END ) AS ph_school_time ",
            "FROM (",
            "SELECT *, ",
            "GROUP_CONCAT( time_start_end ORDER BY t.week_dates ) AS school_time ",
            "FROM (",
            "SELECT t1.id,t1.year_part,t1.quarter_num,t1.student_id,t1.subjects_id,t2.week_dates,",
            "CONCAT( getWeekdayName ( t2.week_dates ), '', t2.time_start, ' - ', t2.time_end ) AS time_start_end ",
            "FROM ",
            "xmy_erp_db.student_grade AS t1 ",
            "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id ",
            "WHERE ",
            "t1.year_part = ${yearPart} ",
            "AND t1.quarter_num = ${quarterNum} ",
            "AND t1.lesson_type &lt;&gt; 1",
            "AND t1.deleted = 0 ",
            "AND t1.`status` = 1 ",
            "<if test= 'readingType == 1'>",
            "<if test= 'isBeforQuarter == 0'>",
            "AND t1.reading_status = 1 ",
            "</if>",
            "<if test= 'isBeforQuarter == 1'>",
            "AND t1.reading_status IN (1,3,4,5,6 ) ",
            "</if>",
            "</if>",
            "<if test= 'readingType == 2'>",
            "AND t1.reading_status IN (1,3,4,5,6 ) ",
            "</if>",
            "GROUP BY t1.grade_id,t1.student_id,t1.subjects_id ",
            ") AS t ",
            "GROUP BY student_id,subjects_id ",
            ") AS t ",
            "GROUP BY student_id",
            ")",
            "<when test= 'examSchedulingtType == 1'>",
            ", wi_tb01 AS ( ",
            "SELECT",
            "rc.student_id",
            "FROM",
            "xmy_erp_db.record_course AS rc where",
            "rc.subjects_id = ${subjectsId}",
            "AND rc.year_part = ${yearPart}",
            "AND rc.quarter = ${quarterNum}",
            "AND rc.lesson_type = 3 ",
            "AND rc.deleted = 0",
            "AND rc.course_type &lt;&gt; 7",
            "AND rc.school_date BETWEEN #{schoolDateStart} AND #{schoolDateEnd}",
            ")",
            "<when test='isIncludeFirstCourse == 1'>",
                " ,record_course_with01 as (select id,year_part,`quarter`,subjects_id,student_id from xmy_erp_db.record_course where year_part = ${yearPart} and `quarter` = ${quarterNum} and lesson_num =1 and lesson_type =1 and course_type =1 and deleted =0 GROUP BY student_id)",
            "</when>",
            "</when>",

            "<when test= 'examSchedulingtType == 2'>",
            ", wi_tb01 AS (",
            "SELECT",
            " t1.student_id",
            " FROM",
            "xmy_erp_db.student_grade AS t1",
            "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id",
            "INNER JOIN xmy_erp_db.course_scheduling_detail AS t3 ON t1.grade_id = t3.grade_id and t3.deleted = 0",
            "  WHERE",
            "t1.year_part = ${yearPart}",
            "AND t1.quarter_num = ${quarterNum}",
            "and t1.deleted = 0",
            "AND t2.lesson_type = 3",
            "AND t1.reading_status = 1",
            "AND t1.subjects_id = ${subjectsId}",
            "AND t3.school_date BETWEEN #{schoolDateStart} AND #{schoolDateEnd}",
            "GROUP BY",
            " t1.student_id",
            "  )",
                "<when test='isIncludeFirstCourse == 1'>",
                    " ,record_course_with01 as (select id,year_part,`quarter`,subjects_id,student_id from xmy_erp_db.record_course where year_part = ${yearPart} and `quarter` = ${quarterNum} and lesson_num =1 and lesson_type =1 and course_type =1 and deleted =0 GROUP BY student_id)",
                "</when>",
            "</when>",

            "SELECT",
            "*,if(brush_count_temp = 0,1,brush_count_temp) as brush_count  ",
            "<when test='listState != 1 and listState != 2'>",
            ",pass_date_time1 AS pass_date_time ",
            "</when>",
            "<when test='listState == 1 or listState == 2'>",
            ",MAX( pass_date_time1 ) AS pass_date_time ",
            "</when>",
            "<when test='listState == 2'>",// 正确率学员详情，为了不影响其他的合并课次数据，所以改成了2，为1的不适用于正确率
            ",GROUP_CONCAT( lesson_num ) AS LessonNumNot,",
            "SUM(lowest_shutnum) AS lowestShutnumAll,",
            "SUM(right_num) AS rightNumAll,",
            "SUM(amend_num) AS amendNumAll",
            "</when>",
            "FROM",
            "(",
            "SELECT",
            "t01.id,",
            "t01.subjects_id,",
            "t01.school_id,",
            "t01.year_part,",
            "t01.quarter_num,",
            "t02.course_version_id,",
            "t01.grade_id,",
            "t01.teacher_id,",
            "t01.class_type_id,",
            "t01.year_class_id,",
            "t01.student_id,",
            "t01.linkman_phone,",
            "t02.task_course_num AS lesson_num,",
            "t02.not_brush,",
            "t03.is_first,",
            "t03.is_last,",
            "t07.en_school_time,",
            "t07.ma_school_time,",
            "t07.ph_school_time,",
            "t04.id AS again_brush_id, ",
            "IFNULL( t03.brush_count,0) as brush_count_temp,",
            "IFNULL( t03.brush_count &gt; 0 AND t03.lowest_shutnum &lt;&gt; 0 AND t03.lowest_shutnum IS NOT NULL, 1) AS yet_finish_count, ",// 已完成
            "IFNULL( t03.is_first = 1 AND (( t03.right_num / t03.lowest_shutnum )* 100 &lt; t03.pass_rade ) AND t03.lowest_shutnum &lt;&gt; 0 AND t03.lowest_shutnum IS NOT NULL AND t04.id IS NOT NULL , 1 ) AS yet_rebrush_count,",// 已复刷
            "IFNULL( t03.pass_rade,t02.pass_rade) as pass_rade, ",
            "( CASE WHEN t03.right_num IS NOT NULL AND t03.pass_rade &gt; 0 and (t03.right_num + t03.amend_num ) &gt;= t03.lowest_shutnum AND ( t03.right_num / t03.lowest_shutnum )* 100 &gt;= t03.pass_rade THEN t03.lowest_shutnum ELSE t02.lowest_shutnum END ) AS lowest_shutnum,",
            "IFNULL( t03.right_num, 0 ) AS right_num,",
            "IFNULL( t03.amend_num, 0 ) AS amend_num,",
            "t03.add_date, ",
            "t05.in_school_time, ",
            "t03.pass_date_time as pass_date_time1",
            "FROM",
            "(",
            "<when test= 'moldType == 1'>",
            "SELECT",
            "t1.*,",
            "t1.class_type_id_new AS class_type_id,",
            "t2.teacher_id,",
            "t5.linkman_phone",
            "FROM",
            "xmy_erp_db.student_grade AS t1",
            "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id ",
            "INNER JOIN per_student_account AS t3 ON t1.student_id = t3.student_id",

            // 已过刷题排班和未到刷题排班
            "INNER JOIN wi_tb01 on t1.student_id = wi_tb01.student_id  ",

            "INNER JOIN xmy_erp_db.student AS t5 ON t1.student_id = t5.id ",
            "LEFT JOIN xmy_erp_db.rade_exclude_student AS t4 ON t4.classify_id = 0 AND t4.deleted = 0 AND t4.type = 2 AND t1.student_id = t4.student_id AND t1.year_part = t4.year_part AND t1.quarter_num = t4.quarter_num AND ( FIND_IN_SET( t1.subjects_id, t4.subjects_ids ) OR t4.subjects_ids IS NULL ) AND ( FIND_IN_SET( t1.school_id, t4.school_ids ) OR t4.school_ids IS NULL ) ",
            "WHERE",
            "t1.year_part = ${yearPart} ",
            "AND t1.quarter_num = ${quarterNum}",
            "AND t1.lesson_type = 1",
            "AND t1.deleted = 0 ",
            "AND t1.subjects_id = ${subjectsId} ",
            "AND t1.is_last = 1 ",
            "<when test='include!=null and include!=&apos;&apos; and isIncludeFirstCourse == 0'>",
            "<when test='include == 0'>",
            "and t4.id is null ",
            "</when>",
            "<when test='include == 1'>",
            "and t4.id is not null ",
            "</when>",
            "</when>",
            "<when test='isBeforQuarter == 0 and readingType == 1'>",
            "AND t1.reading_status IN (1,5) ",
            "</when>",
            "<when test='isBeforQuarter == 1 and readingType == 1'>",
            "AND t1.reading_status IN (1,5)",
            "</when>",
            "<when test='readingType == 2'>",
            "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and use_course_count > 0)) ",
            "</when>",
            "AND t1.STATUS &lt;&gt; 3 ",
            "AND t1.deleted = 0 ",
            "<when test='gradeId!=null and gradeId!=&apos;&apos;'>",
            "and t1.grade_id = ${gradeId}",
            "</when>",
            "<when test='studentName!=null and studentName!=&apos;&apos;'>",
            "AND t1.student_id IN (SELECT id FROM xmy_erp_db.student WHERE `name` LIKE '%${studentName}%' AND `status` = 1 AND deleted = 0)",
            "</when>",
//            "<when test='schoolIdStr!=null and schoolIdStr!=&apos;&apos; and (type == 2 || type==4)'>",
//            "and t1.school_id in(${schoolIdStr})",
//            "</when>",
//            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
//            "and t2.year_class_id in(${yearClassIdStr})",
//            "</when>",
//            "<when test='yearClassIdStr==null or yearClassIdStr==&apos;&apos; '>",
//            "and t2.year_class_id &lt; 13",
//            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and t1.class_type_id_new IN (${classTypeId})",
            "</when>",
//            "<when test='teacherId!=null and teacherId!=&apos;&apos; and type != 4'>",
//            "  and t2.teacher_id = ${teacherId}",
//            "</when>",

            "and(",
            "(",
            "t1.school_id IN (${schoolIdStr})",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos;'>",
            "AND t2.year_class_id IN (${yearClassIdStr})",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
            "AND t2.teacher_id = ${teacherId}",
            "</when>",
            ")",
            "or",
            "(",
            "t1.school_id IN (${leadSchoolIds})",
            "and t2.year_class_id IN (${leadYearClassIds})",
            "and t2.teacher_id IN (${leadTeacherId})",
            ")",
            ")",

            "GROUP BY",
            "student_id ",
            "</when>",

            "<when test= 'moldType == 2'>",
            "SELECT",
            "t02.*, ",
            "t02.class_type_id_new AS class_type_id,",
            "t03.teacher_id,",
            "t03.`name` AS grade_name,",
            "staff.`name` AS teacher_name, ",
            "t06.linkman_phone ",
            "FROM",
            "(",
            "SELECT",
            "t1.school_id,",
            "t1.old_teacher_id AS teacher_id,",
            "t1.student_id,",
            "t1.`status`,",
            "t1.reach_type,",
            "t1.old_grade_id AS grade_id,",
            "t1.subjects_id,",
            "t1.year_class_id,",
            "t1.time_start,",
            "t1.time_end,",
            "t1.course_type, ",
            "t1.lesson_num,",
            "t1.school_date,",
            "t10.year_part,",
            "t10.quarter_num ",
            "FROM",
            "xmy_erp_db.record_course AS t1 ",
            "INNER JOIN xmy_erp_db.grade AS t10 ON t1.grade_id = t10.id AND t10.is_rebrush = 0 ",
            "WHERE",
            "t1.deleted = 0 ",
            "AND t1.year_part = ${yearPart} ",
            "AND t1.`quarter` = ${quarterNum} ",
            "AND t1.`lesson_type` = 3 ",
            "AND t1.old_teacher_id IS NOT NULL ",
            "AND ((t1.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ) OR ( t1.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' AND t1.course_type = 7 )) ",

            "UNION ALL ",

            "SELECT",
            "t4.school_id,",
            "t4.teacher_id,",
            "t1.student_id,",
            "t5.`status`,",
            "t5.reach_type,",
            "t6.grade_id,",
            "t2.subjects_id,",
            "t4.year_class_id,",
            "t2.time_start,",
            "t2.time_end,",
            "1 AS course_type, ",
            "t2.lesson_num,",
            "t2.school_date, ",
            "t10.year_part,",
            "t10.quarter_num ",
            "FROM",
            "xmy_erp_db.${courseSchedulingDetailName} AS t2",
            "INNER JOIN xmy_erp_db.grade AS t10 ON t2.grade_id = t10.id AND t10.is_rebrush = 0 ",
            "INNER JOIN xmy_erp_db.student_grade AS t1 ON t2.year_part = t1.year_part ",
            "AND t2.`quarter` = t1.quarter_num ",
            "AND t2.deleted = t1.deleted ",
            "AND t2.grade_id = t1.grade_id ",
            "AND t2.lesson_type = t1.lesson_type ",
            "<when test='isBeforQuarter == 0 and readingType == 1'>",
            "AND t1.reading_status IN (1,5) ",
            "</when>",
            "<when test='isBeforQuarter == 1 and readingType == 1'>",
            "AND t1.reading_status IN (1,5)",
            "</when>",
            "<when test='readingType == 2'>",
            "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and t1.use_course_count > 0)) ",
            "</when>",
            "AND t1.`status` = 1",
            "INNER JOIN xmy_erp_db.student_grade AS t6 ON t6.year_part = t1.year_part ",
            "AND t6.`quarter_num` = t1.quarter_num ",
            "AND t6.deleted = t1.deleted ",
            "AND t6.subjects_id = t1.subjects_id ",
            "AND t6.`student_id` = t1.student_id ",
            "AND t6.lesson_type = 1 ",
            "<when test='isBeforQuarter == 0 and readingType == 1'>",
            "AND t6.reading_status IN (1,5) ",
            "</when>",
            "<when test='isBeforQuarter == 1 and readingType == 1'>",
            "AND t6.reading_status IN (1,5)",
            "</when>",
            "<when test='readingType == 2'>",
            "AND ((t6.reading_status IN (1,5)) or (t6.reading_status in(3,4) and t6.use_course_count > 0)) ",
            "</when>",
            "AND t6.`status` = 1",
            "and t2.end_date_time &gt;= t6.created_at",
            "LEFT JOIN xmy_erp_db.repair_course AS t3 ON t3.out_scheduling_detail_id = t2.id AND t3.deleted = 0",
            "AND t3.student_id = t1.student_id",
            "LEFT JOIN xmy_erp_db.grade AS t4 ON t6.grade_id = t4.id",
            "LEFT JOIN xmy_erp_db.record_course AS t5 ON t5.scheduling_detail_id = t2.id ",
            "AND t5.student_id = t1.student_id ",
            "AND t5.deleted = 0 ",
            "WHERE",
            "t2.year_part = ${yearPart} ",
            "AND t2.`quarter` = ${quarterNum} ",
            "AND t2.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
            "AND t2.lesson_type = 3 ",
            "AND t2.deleted = 0 ",
            "AND t2.`status` &lt;&gt; 2 ",
            "AND t3.id IS NULL ",
            "GROUP BY",
            "t2.id,",
            "t1.school_id,",
            "t1.subjects_id,",
            "t1.student_id,",
            "t1.lesson_type ",
            ") AS t01",
            "INNER JOIN xmy_erp_db.student_grade AS t02 ON t01.student_id = t02.student_id ",
            "AND t01.subjects_id = t02.subjects_id ",
            "AND t01.year_part = t02.year_part ",
            "AND t01.quarter_num = t02.quarter_num ",
            "AND t02.lesson_type = 1 ",
            "AND t02.deleted = 0 ",
            "AND t02.is_last = 1 ",
            "INNER JOIN xmy_erp_db.grade AS t03 ON t02.grade_id = t03.id ",
            "INNER JOIN xmy_erp_db.staff ON staff.id = t03.teacher_id ",
            "LEFT JOIN xmy_erp_db.rade_exclude_student AS t04 ON t04.classify_id = 0 ",
            "AND t04.deleted = 0 ",
            "AND t04.type = 2 ",
            "AND t02.student_id = t04.student_id ",
            "AND t02.year_part = t04.year_part ",
            "AND t02.quarter_num = t04.quarter_num ",
            "AND ( FIND_IN_SET( t02.subjects_id, t04.subjects_ids ) OR t04.subjects_ids IS NULL ) ",
            "AND ( FIND_IN_SET( t02.school_id, t04.school_ids ) OR t04.school_ids IS NULL ) ",
            "INNER JOIN per_student_account AS t05 ON t05.student_id = t01.student_id ",
            "INNER JOIN xmy_erp_db.student AS t06 ON t01.student_id = t06.id ",
            "LEFT JOIN xmy_erp_db.cha_study_plan AS csp ON t01.student_id = csp.student_id ",
            "AND csp.subjects_id = t01.subjects_id ",
            "AND csp.lesson_type = 3 ",
            "AND csp.`status` = 1 ",
            "AND csp.year_part = ${yearPart}",
            "AND csp.quarter_num = ${quarterNum} ",
            "AND school_date BETWEEN csp.start_task_date AND csp.end_task_date ",
            "AND DATE(csp.created_at) &lt; school_date ",
            "WHERE ",
//                            "((t01.`status` = 1 AND course_type &lt;&gt; 7 ) OR ( course_type = 7 )) ",
            "t01.`status` = 1 ",
            "AND t02.`status` &lt;&gt; 3 ",
            "AND t03.year_part = ${yearPart} ",
            "AND t03.quarter_num = ${quarterNum} ",
            "AND t03.lesson_type = 1 ",
            "AND csp.student_id IS NULL",
            "AND t03.subjects_id IN (${subjectsId}) ",
//            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
//            "AND t03.year_class_id in(${yearClassIdStr}) ",
//            "</when>",
//            "<when test='yearClassIdStr==null or yearClassIdStr==&apos;&apos; '>",
//            "AND t03.year_class_id &lt; 13 ",
//            "</when>",
            "<when test='include!=null and include!=&apos;&apos; and isIncludeFirstCourse == 0'>",
            "<when test='include == 0'>",
            "and t04.id IS NULL  ",
            "</when>",
            "<when test='include == 1'>",
            "and t04.id IS NOT NULL  ",
            "</when>",
            "</when>",
            "<when test='isBeforQuarter == 0 and readingType == 1'>",
            "AND t02.reading_status IN (1,5) ",
            "</when>",
            "<when test='isBeforQuarter == 1 and readingType == 1'>",
            "AND t02.reading_status IN (1,5)",
            "</when>",
            "<when test='readingType == 2'>",
            "AND ((t02.reading_status IN (1,5)) or (t02.reading_status in(3,4) and t02.use_course_count > 0)) ",
            "</when>",
//            "<when test='schoolIdStr!=null and schoolIdStr!=&apos;&apos; and (type == 2 || type == 4)'>",
//            "AND t03.school_id in(${schoolIdStr}) ",
//            "</when>",
//            "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
//            "AND t03.teacher_id in(${teacherId}) ",
//            "</when>",

            "and(",
            "(",
            "t03.school_id IN (${schoolIdStr})",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos;'>",
            "AND t03.year_class_id IN (${yearClassIdStr})",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
            "AND t03.teacher_id = ${teacherId}",
            "</when>",
            ")",
            "or",
            "(",
            "t03.school_id IN (${leadSchoolIds})",
            "and t03.year_class_id IN (${leadYearClassIds})",
            "and t03.teacher_id IN (${leadTeacherId})",
            ")",
            ")",

            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "AND t02.class_type_id_new IN (${classTypeId}) ",
            "</when>",
            "GROUP BY student_id",
            "</when>",

            ") AS t01",

            "<when test='isIncludeFirstCourse == 1'>",
            "LEFT JOIN record_course_with01 as t06 on t01.student_id = t06.student_id and t01.subjects_id = t06.subjects_id",
            "</when>",

            "INNER JOIN ( SELECT * FROM edu_task WHERE deleted = 0 and task_category_id = ${taskCategoryId} and subjects_id = ${subjectsId} and task_course_num BETWEEN ${lessonNumStart} and ${lessonNum}) AS t02 ON t01.year_part = t02.year_part ",
            "AND t01.quarter_num = t02.quarter_num ",
            "AND t01.subjects_id = t02.subjects_id ",
            "AND t01.class_type_id = t02.class_type_id",
            "AND t01.year_class_id = t02.year_class_id",
            "<when test='(inType != 2)'>",
            "LEFT ",
            "</when>",
            "<when test='(inType == 2)'>",
            "INNER",
            "</when>",
            "JOIN (SELECT",
            "student_id,",
            "add_date,",
            "lesson_num_finish,",
            "year_class_id,",
            "course_version_id,",
            "class_type_id,",
            "year_part,",
            "quarter_num,",
            "IFNULL( lesson_num, 0 ) AS lesson_num,",
            "right_num,",
            "is_last,",
            "is_first,",
            "amend_num, ",
            "lowest_shutnum, ",
            "brush_count, ",
            "pass_rade,",
            "pass_date_time ",
            "FROM",
            "cha_plan ",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND quarter_num = ${quarterNum}",
            "AND task_category_id = ${taskCategoryId}",
            "and deleted = 0",
            "<when test='rightNumStartDate != &apos;&apos; and rightNumEndDate != &apos;&apos;'>",
            "AND add_date BETWEEN '${rightNumStartDate}' AND '${rightNumEndDate}' ",
            "AND right_num &gt; 0 ",
            "</when>",
            ") AS t03 ON t01.year_part = t03.year_part ",
            "AND t01.quarter_num = t03.quarter_num ",
            "AND t01.student_id = t03.student_id ",
            "AND t02.year_class_id = t03.year_class_id ",
            "AND t02.class_type_id = t03.class_type_id ",
            "AND t02.course_version_id = t03.course_version_id",
            "<when test='courseVersionId!=null and courseVersionId!=&apos;&apos;'>",
            "and t02.course_version_id = ${courseVersionId}",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and t01.subjects_id = ${subjectsId}",
            "</when>",
            //"<when test='isAll == 0'>",
            //    "AND t02.task_course_num = t03.lesson_num",
            //    "AND t02.task_course_num = t03.lesson_num_finish",
            //"</when>",
            //"<when test='isAll == 1'>",
            //    "AND t02.task_course_num = t03.lesson_num",
            //    "and t03.is_last = 1",
            //"</when>",
            "AND t02.task_course_num = t03.lesson_num",
            "<when test='radeType!=null and radeType == 1 '>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType != 9 and passType != 10 and passType != 11 and passType != 12'>",
            "and t03.is_last = 1",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and (passType == 9 or passType == 10 or passType == 11 or passType == 12 )'>",
            "and t03.is_first = 1",
            "</when>",
            "</when>",
            "<when test='radeType!=null and (radeType == 2 or radeType == 3) '>",
            "and t03.is_first = 1",
            "</when>",

            "LEFT JOIN ( ",
            "SELECT",
            "id,",
            "student_id,",
            "add_date,",
            "lesson_num_finish,",
            "year_class_id,",
            "course_version_id,",
            "class_type_id,",
            "year_part,",
            "quarter_num,",
            "IFNULL( lesson_num, 0 ) AS lesson_num,",
            "right_num,",
            "is_last,",
            "is_first,",
            "amend_num,",
            "pass_rade,",
            "brush_count,",
            "lowest_shutnum",
            "FROM",
            "cha_plan",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND quarter_num = ${quarterNum} ",
            "AND task_category_id = ${taskCategoryId} ",
            "AND deleted = 0",
            ") AS t04 ON t04.year_part = t03.year_part ",
            "AND t04.quarter_num = t03.quarter_num ",
            "AND t04.student_id = t03.student_id ",
            "AND t04.year_class_id = t03.year_class_id ",
            "AND t04.course_version_id = t03.course_version_id ",
            "AND t04.class_type_id = t03.class_type_id ",
            "AND t04.lesson_num = t03.lesson_num ",
            "and t04.is_last = 1 ",
            "and t04.is_first = 0 ",
            // 计算在校时长：
            // 正常情况：签退时间-签到时间 = 在校时间
            // 签到时间为空：如果当前时间和add_date是同一天，并且当前时间没有超过23点，那么使用当前时间减去签到时间，计算在校时间
            // 签到时间为空：如果当前时间和add_date是同一天，并且当前时间超过23点，那么显示“无效”
            // 签到时间为空：如果当前时间和add_date不是同一天，那么显示“无效”
            // 多选日期，在校时长相加，并且不计算无效时间数据
            "LEFT JOIN ( ",
            "SELECT",
            "student_id,subjects_id,IF(SUM(in_school_time) = 0, '无效', IFNULL(SUM(in_school_time), 0)) AS in_school_time ",
            "FROM ",
            "( ",
            "SELECT t1.student_id,t1.subjects_id,t1.school_date,",
            "CASE ",
            "WHEN in_date_time IS NOT NULL AND out_date_time IS NOT NULL THEN TIMESTAMPDIFF( MINUTE, in_date_time, out_date_time ) ",
            "WHEN in_date_time IS NOT NULL AND out_date_time IS NULL THEN ",
            "CASE ",
            "WHEN DATE ( add_date ) = CURDATE() AND HOUR (NOW()) &lt; 23 THEN TIMESTAMPDIFF( MINUTE, in_date_time, NOW()) ",
            "WHEN DATE ( add_date ) = CURDATE() AND HOUR ( NOW()) &gt;= 23 THEN 0 ELSE 0 END ELSE 0 END AS in_school_time ",
            "FROM",
            "xmy_erp_db.record_course AS t1 ",
            "LEFT JOIN xmy_erp_db.student_sign_in AS t2 ON t1.scheduling_detail_id = t2.scheduling_detail_id AND t1.student_id = t2.student_id AND t2.add_date = t1.school_date AND t2.subjects_id = t1.subjects_id",
            "WHERE ",
            "t1.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
            "AND t1.lesson_type = 3",
            "AND t1.subjects_id = ${subjectsId}",
            ") AS student_sign_in ",
            "GROUP BY ",
            "student_id ",
            ") t05 ON t05.student_id = t01.student_id AND t05.subjects_id = t01.subjects_id ",
            "LEFT JOIN tb_school_time_01 AS t07 ON t01.year_part = t07.year_part AND t01.quarter_num = t07.quarter_num AND t01.student_id = t07.student_id ",
//                        "GROUP BY t01.student_id",
            "where 1=1",
            "<when test='include!=null and include!=&apos;&apos; and isIncludeFirstCourse = 1'>",
                "<when test='include == 0'>",
                    "and t06.id is not null",
                "</when>",
                "<when test='include == 1'>",
                    "and t06.id is null",
                "</when>",
            "</when>",
            ") AS t",
            "where 1=1",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 2'>",// 已通关
            " AND ((( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR ( brush_count_temp &gt;= 2 AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR ( not_brush = 1 AND ( right_num + amend_num ) &gt;= lowest_shutnum )) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
//                    " AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND ( right_num + amend_num &gt;= lowest_shutnum ) AND lowest_shutnum &lt;&gt; 0 and lowest_shutnum IS NOT NULL",
//                    " AND ( right_num + amend_num ) &gt;= lowest_shutnum AND lowest_shutnum &lt;&gt; 0",
//                    " AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND lowest_shutnum &lt;&gt; 0",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 3'>",// 未通关
            " AND ((not_brush = 0 and brush_count_temp &lt;= 1 AND (right_num / lowest_shutnum )* 100 &lt; pass_rade ) OR ( not_brush = 0 and brush_count_temp &gt;= 2 AND ( right_num + amend_num ) &lt; lowest_shutnum ) OR (( right_num / lowest_shutnum )* 100 &gt;= pass_rade  AND ( right_num + amend_num ) &lt; lowest_shutnum ) OR ( not_brush = 1 AND ( right_num + amend_num ) &lt; lowest_shutnum )) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
//                    " AND ((( right_num / lowest_shutnum )* 100 &lt; pass_rade) OR ((right_num / lowest_shutnum * 100 &gt;= pass_rade) AND (right_num + amend_num &lt; lowest_shutnum))) AND lowest_shutnum &lt;&gt; 0 ",
//                    " AND (  ( right_num + amend_num ) &lt; lowest_shutnum and lowest_shutnum &lt;&gt; 0)",
//                    " AND (  ( right_num / lowest_shutnum )* 100 &lt; pass_rade and lowest_shutnum &lt;&gt; 0)",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 4'>",// 今日已通关
            " AND ((( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR ( brush_count_temp &gt;= 2 AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR (not_brush = 1 and ( right_num + amend_num ) &gt;= lowest_shutnum)) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
//                    " AND ( right_num + amend_num ) &gt;= lowest_shutnum AND lowest_shutnum &lt;&gt; 0",
//                    " AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND lowest_shutnum &lt;&gt; 0 ",
            "and add_date BETWEEN '${passDateStart}' AND '${passDateEnd}'",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 5'>",// 未刷（未完成）
            "and brush_count_temp = 0 AND (right_num =0 and amend_num=0  and lowest_shutnum is not null)",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 6'>", // 通关率——>需复刷
//                        "AND brush_count_temp &gt;= 1 AND brush_count_temp &lt;= 2 AND (right_num + amend_num) &lt; lowest_shutnum AND lowest_shutnum &lt;&gt; 0",
            "and not_brush = 0 AND brush_count_temp &gt;= 1 AND (brush_count_temp &lt; 2 OR (right_num + amend_num &lt; lowest_shutnum)) AND ((( right_num / lowest_shutnum )* 100 &lt; pass_rade) OR ((right_num / lowest_shutnum * 100 &gt;= pass_rade) AND (right_num + amend_num &lt; lowest_shutnum))) AND lowest_shutnum &lt;&gt; 0",
//                        "and brush_count_temp &gt;= 1 AND ((( right_num / lowest_shutnum )* 100 &lt; pass_rade ) and lowest_shutnum &lt;&gt; 0)",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 7'>",// 第一种已完成详情（录了就算已完成）
            "AND brush_count_temp &gt; 0 AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 8'>",// 第一种根据日期已完成详情（录了就算已完成）
            "AND brush_count_temp &gt; 0 AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL",
            "and add_date BETWEEN '${passDateStart}' AND '${passDateEnd}'",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 9'>",// 应复刷详情
            "AND is_first = 1  ",
            "AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade )",
            "AND lowest_shutnum &lt;&gt; 0 ",
            "AND lowest_shutnum IS NOT NULL ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 10'>",// 已复刷详情
            "AND is_first = 1 ",
            "AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade ) ",
            "AND lowest_shutnum &lt;&gt; 0 ",
            "AND lowest_shutnum IS NOT NULL ",
            "AND again_brush_id IS NOT NULL ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 11'>",// 根据日期已复刷详情
            "AND is_first = 1 ",
            "AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade ) ",
            "AND lowest_shutnum &lt;&gt; 0 ",
            "AND lowest_shutnum IS NOT NULL ",
            "AND again_brush_id IS NOT NULL ",
            "and add_date BETWEEN '${passDateStart}' AND '${passDateEnd}'",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 12'>",// 未复刷
            "AND is_first = 1  ",
            "AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade )",
            "AND lowest_shutnum &lt;&gt; 0 ",
            "AND lowest_shutnum IS NOT NULL ",
            "AND again_brush_id IS NULL ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 13'>",// 应修正
            "AND brush_count_temp &gt;= 1 AND ( right_num + amend_num ) &lt; lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 14'>",// 已完成（正确+修正>=应通关）
            "AND brush_count_temp = 1 AND (right_num + amend_num) &gt;= lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 15'>",// 今日已完成（正确+修正>=应通关）
            "AND brush_count_temp = 1 AND (right_num + amend_num) &gt;= lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 16'>",// 需修正（第一次需修正）
            "AND brush_count_temp = 1 AND ( right_num + amend_num ) &lt; lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 17'>",// 复刷应通关
            "AND (brush_count_temp &gt;= 1 AND (brush_count_temp &lt; 2 OR ( right_num + amend_num &lt; lowest_shutnum )) AND (((right_num / lowest_shutnum )* 100 &lt; pass_rade ) OR (( right_num / lowest_shutnum * 100 &gt;= pass_rade ) AND ( right_num + amend_num &lt; lowest_shutnum ))) OR brush_count_temp &gt;= 2 ) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 18'>",// 复刷已通关
            "AND (( brush_count_temp &gt;= 2 AND (( right_num + amend_num ) &gt;= lowest_shutnum AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade ))) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 19'>",// 复刷未通关
            "AND ( brush_count_temp &gt;= 1 AND (( right_num + amend_num ) &lt; lowest_shutnum OR ( right_num / lowest_shutnum )* 100 &lt; pass_rade )) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 20'>",// 复刷今日已通关
            "AND (( brush_count_temp &gt;= 2 AND (( right_num + amend_num ) &gt;= lowest_shutnum AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade ))) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL",
            "AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
            "</when>",
            "<when test='studentIdStr!=null and studentIdStr!=&apos;&apos; '>",
            "AND student_id IN (${studentIdStr}) ",
            "</when>",
            "<when test='listState == 1 or listState == 2'>",
            "GROUP BY student_id",
            "</when>",
            "ORDER BY pass_date_time IS NULL ASC,pass_date_time ASC,student_id,lesson_num ASC",
            "</script>"})
    public IPage<ChaPlan> getPassedBrushiDetail(IPage<?> page,
                                            @Param("yearPart") String yearPart,
                                            @Param("quarterNum") String quarterNum,
                                            @Param("schoolIdStr") String schoolIdStr,
                                            @Param("teacherId") String teacherId,
                                            @Param("yearClassIdStr") String yearClassIdStr,
                                            @Param("type") String type,
                                            @Param("gradeId") String gradeId,
                                            @Param("lessonNumStart") String lessonNumStart,
                                            @Param("lessonNum") String lessonNum,
                                            @Param("classTypeId") String classTypeId,
                                            @Param("readingType") String readingType,
                                            @Param("passType") String passType,
                                            @Param("lessonNow") String lessonNow,
                                            @Param("isAll") String isAll,
                                            @Param("courseVersionId") Long courseVersionId,
                                            @Param("passDate") String passDate,
                                            @Param("passDateStart") String passDateStart,
                                            @Param("passDateEnd") String passDateEnd,
                                            @Param("subjectsId") Long subjectsId,
                                            @Param("isBeforQuarter") String isBeforQuarter,
                                            @Param("readingStatusStr") String readingStatusStr,
                                            @Param("rightNumStartDate") String rightNumStartDate,
                                            @Param("rightNumEndDate") String rightNumEndDate,
                                            @Param("studentName") String studentName,
                                            @Param("radeType") String radeType,
                                            @Param("listState") String listState,
                                            @Param("include") String include,
                                            @Param("inType") String inType,
                                            @Param("taskCategoryId") Integer taskCategoryId,
                                            @Param("courseSchedulingDetailName") String courseSchedulingDetailName,
                                            @Param("studentIdStr") String studentIdStr,
                                            @Param("moldType") String moldType,  // 1、正常通关率 2、到勤通关率
                                            @Param("schoolDateStart") String schoolDateStart,
                                            @Param("schoolDateEnd") String schoolDateEnd,
                                            @Param("examSchedulingtType") String examSchedulingtType,
                                            @Param("leadSchoolIds") String leadSchoolIds,
                                            @Param("leadSubjectsIds") String leadSubjectsIds,
                                            @Param("leadYearClassIds") String leadYearClassIds,
                                            @Param("leadTeacherId") Long leadTeacherId,
                                            @Param("isIncludeFirstCourse") String isIncludeFirstCourse
    );




    /**
     * 合计
     * @param
     * @param yearPart
     * @param quarterNum
     * @param schoolIdStr
     * @param teacherId
     * @param yearClassIdStr
     * @param type
     * @param gradeId
     * @param lessonNumStart
     * @param lessonNum
     * @param classTypeId
     * @param passType
     * @param lessonNow
     * @param isAll
     * @param courseVersionId
     * @param subjectsId
     * @param readingStatusStr
     * @return
     */
    @Select({"<script>",
            "SELECT",
            "SUM( lowest_shutnum ) AS lowest_shutnum,",
            "SUM( right_num ) AS right_num,",
            "SUM( amend_num ) AS amend_num,",
            "if(brush_count_temp =0,1,brush_count_temp) as brush_count",
            "FROM",
            "(",
            "SELECT",
            "t01.id,",
            "t01.school_id,",
            "t01.year_part,",
            "t01.quarter_num,",
            "t02.course_version_id,",
            "t01.grade_id,",
            "t01.teacher_id,",
            "t01.class_type_id,",
            "t01.year_class_id,",
            "t01.student_id,",
            "t02.task_course_num AS lesson_num,",
            "( CASE WHEN t03.right_num IS NOT NULL  AND t03.pass_rade > 0  AND ( right_num + amend_num ) >= t03.lowest_shutnum  AND ( t03.right_num / t03.lowest_shutnum )* 100 >= t03.pass_rade THEN t03.lowest_shutnum ELSE t02.lowest_shutnum  END ) AS lowest_shutnum,",
            "IFNULL( t03.right_num, 0 ) AS right_num,",
            "IFNULL( t03.amend_num, 0 ) AS amend_num,",
            "ifnull(t03.brush_count,0) as brush_count_temp,",
            "t03.pass_rade,",
            "add_date ",
            "FROM",
            "(",
            "SELECT",
            "t1.*,",
            //"t2.course_type_id AS class_type_id,",
            "t1.class_type_id_new AS class_type_id,",
            "t2.teacher_id ",
            "FROM",
            "xmy_erp_db.student_grade AS t1",
            "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id ",
            "INNER JOIN per_student_account AS t3 ON t1.student_id = t3.student_id",
            "LEFT JOIN xmy_erp_db.rade_exclude_student AS t4 ON t4.classify_id = 0 AND t4.deleted = 0 AND t4.type = 2 AND t1.student_id = t4.student_id AND t1.year_part = t4.year_part AND t1.quarter_num = t4.quarter_num AND ( FIND_IN_SET( t1.subjects_id, t4.subjects_ids ) OR t4.subjects_ids IS NULL ) AND ( FIND_IN_SET( t1.school_id, t4.school_ids ) OR t4.school_ids IS NULL ) ",
            "WHERE",
            "t1.year_part = ${yearPart} ",
            "AND t1.quarter_num = ${quarterNum}",
            "AND t1.lesson_type = 1",
            "AND t1.deleted = 0 ",
            "AND t1.subjects_id = ${subjectsId} ",
            "AND t1.is_last = 1 ",
            "<when test='include!=null and include!=&apos;&apos;'>",
                "<when test='include == 0'>",
                    "and t4.id is null ",
                "</when>",
                "<when test='include == 1'>",
                    "and t4.id is not null ",
                "</when>",
            "</when>",
            "<when test='isBeforQuarter == 0 and readingType == 1'>",
                "AND t1.reading_status IN (1,5) ",
            "</when>",
            "<when test='isBeforQuarter == 1 and readingType == 1'>",
                "AND t1.reading_status IN (1,5)",
            "</when>",
            "<when test='readingType == 2'>",
                "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and use_course_count > 0)) ",
            "</when>",
            "AND t1.STATUS &lt;&gt; 3 ",
            "AND t1.deleted = 0 ",
            "<when test='gradeId!=null and gradeId!=&apos;&apos;'>",
            "and t1.grade_id = ${gradeId}",
            "</when>",
            "<when test='studentName!=null and studentName!=&apos;&apos;'>",
            "AND t1.student_id IN (SELECT id FROM xmy_erp_db.student WHERE `name` LIKE '%${studentName}%' AND `status` = 1 AND deleted = 0)",
            "</when>",
            "<when test='schoolIdStr!=null and schoolIdStr!=&apos;&apos; and (type == 2 || type==4)'>",
            "and t1.school_id in(${schoolIdStr})",
            "</when>",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and t2.year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='yearClassIdStr==null or yearClassIdStr==&apos;&apos; '>",
            "and t2.year_class_id &lt; 13",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and t1.class_type_id_new = ${classTypeId}",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; and type != 4'>",
            "  and t2.teacher_id = ${teacherId}",
            "</when>",
            "GROUP BY",
            "student_id ",
            ") AS t01",
            "LEFT JOIN ( SELECT * FROM edu_task WHERE deleted = 0 and task_category_id =${taskCategoryId} and subjects_id = ${subjectsId} and task_course_num BETWEEN ${lessonNumStart} and ${lessonNum}) AS t02 ON t01.year_part = t02.year_part ",
            "AND t01.quarter_num = t02.quarter_num ",
            "AND t01.subjects_id = t02.subjects_id ",
            "AND t01.class_type_id = t02.class_type_id",
            "AND t01.year_class_id = t02.year_class_id",
            "<when test='(inType != 2)'>",
            "LEFT ",
            "</when>",
            "<when test='(inType == 2)'>",
            "INNER",
            "</when>",
            "JOIN (",
            "SELECT",
            "student_id,",
            "add_date,",
            "lesson_num_finish,",
            "year_class_id,",
            "course_version_id,",
            "class_type_id,",
            "year_part,",
            "quarter_num,",
            "IFNULL( lesson_num, 0 ) AS lesson_num,",
            "right_num,",
            "is_last,",
            "is_first,",
            "amend_num,",
            "lowest_shutnum, ",
            "brush_count, ",
            "pass_rade",
            "FROM",
            "cha_plan ",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND quarter_num = ${quarterNum}",
            "AND task_category_id = ${taskCategoryId}",
            "and deleted = 0",
            "<when test='rightNumStartDate != &apos;&apos; and rightNumEndDate != &apos;&apos;'>",
                "AND add_date BETWEEN '${rightNumStartDate}' AND '${rightNumEndDate}' ",
            "</when>",
            ") AS t03 ON t01.year_part = t03.year_part ",
            "AND t01.quarter_num = t03.quarter_num ",
            "AND t01.student_id = t03.student_id ",
            "AND t02.year_class_id = t03.year_class_id ",
            "AND t02.class_type_id = t03.class_type_id ",
            "AND t02.course_version_id = t03.course_version_id",
            "<when test='courseVersionId!=null and courseVersionId!=&apos;&apos;'>",
            "and t02.course_version_id = ${courseVersionId}",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and t01.subjects_id = ${subjectsId}",
            "</when>",
            //"<when test='isAll == 0'>",
            //    "AND t02.task_course_num = t03.lesson_num",
            //    "AND t02.task_course_num = t03.lesson_num_finish",
            //"</when>",
            //"<when test='isAll == 1'>",
            //    "AND t02.task_course_num = t03.lesson_num",
            //    "and t03.is_last = 1",
            //"</when>",
            "AND t02.task_course_num = t03.lesson_num",
            "<when test='radeType!=null and radeType == 1 '>",
            "and t03.is_last = 1",
            "</when>",
            "<when test='radeType!=null and (radeType == 2 or radeType == 3) '>",
            "and t03.is_first = 1",
            "</when>",
            ") AS t",
            "where 1=1",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 2'>",
            "  and lowest_shutnum &lt;= ( right_num + amend_num ) and lowest_shutnum &lt;&gt; 0",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 3'>",
            "  and (lowest_shutnum &gt; ( right_num + amend_num ) or (lowest_shutnum  = 0))",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 4'>",
            "  and lowest_shutnum &lt;= ( right_num + amend_num )",
            "and add_date BETWEEN '${passDateStart}' AND '${passDateEnd}'",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 5'>",
            "and brush_count_temp = 0 AND (right_num =0 and amend_num=0)",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 6'>",
            "and brush_count_temp &gt;= 1 AND ((( right_num / lowest_shutnum )* 100 &lt; pass_rade ) OR ( lowest_shutnum = 0 ))",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 7'>",
            "AND brush_count_temp &gt; 0 AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 8'>",
                "AND brush_count_temp &gt; 0 AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL",
                "and add_date BETWEEN '${passDateStart}' AND '${passDateEnd}'",
            "</when>",
            "</script>"})
    public ChaPlan getPassRadeDetailTotal(@Param("yearPart") String yearPart,
                                          @Param("quarterNum") String quarterNum,
                                          @Param("schoolIdStr") String schoolIdStr,
                                          @Param("teacherId") String teacherId,
                                          @Param("yearClassIdStr") String yearClassIdStr,
                                          @Param("type") String type,
                                          @Param("gradeId") String gradeId,
                                          @Param("lessonNumStart") String lessonNumStart,
                                          @Param("lessonNum") String lessonNum,
                                          @Param("classTypeId") String classTypeId,
                                          @Param("readingType") String readingType,
                                          @Param("passType") String passType,
                                          @Param("lessonNow") String lessonNow,
                                          @Param("isAll") String isAll,
                                          @Param("courseVersionId") Long courseVersionId,
                                          @Param("passDate") String passDate,
                                          @Param("passDateStart") String passDateStart,
                                          @Param("passDateEnd") String passDateEnd,
                                          @Param("subjectsId") Long subjectsId,
                                          @Param("isBeforQuarter") String isBeforQuarter,
                                          @Param("readingStatusStr") String readingStatusStr,
                                          @Param("rightNumStartDate") String rightNumStartDate,
                                          @Param("rightNumEndDate") String rightNumEndDate,
                                          @Param("studentName") String studentName,
                                          @Param("radeType") String radeType,
                                          @Param("include") String include,
                                          @Param("inType") String inType,
                                          @Param("taskCategoryId") Integer taskCategoryId);

    /**
     * 数学通关率战队
     * @return
     */
    @Select({"<script>",
            "SELECT",
            "t02.*,team_name,team_id,team_pid,",
            "SUM( lowest_shutnum ) AS lowest_shutnum_all,",
            "SUM( right_num ) AS right_num_all,",
            "<when test='rightNumStartDate != &apos;&apos; and rightNumEndDate != &apos;&apos;'>",
            "SUM( right_num_date_no_sum ) AS right_num_date,",
            "</when>",
            "<when test='rightNumStartDate == &apos;&apos; and rightNumEndDate == &apos;&apos;'>",
            "0 AS right_num_date,",
            "</when>",
            "SUM( amend_num ) AS amend_num_all,",
            "SUM( lowest_shutnum - right_num ) AS error_num_all,",

            "SUM( CASE WHEN (lowest_shutnum &lt;&gt; 0 and lowest_shutnum is not null",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            ") THEN 1 ELSE 0 END ) AS show_pass_num,",

            "SUM( CASE WHEN yet_pass_num_temp &gt;=student_all_shutnum and student_all_shutnum &gt; 0 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS yet_pass_num,",

            "SUM( CASE WHEN not_pass_num_temp &gt;0 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS not_pass_num,",

            "SUM( CASE WHEN not_brush_num_temp &gt;0 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS not_brush_num,",

            "SUM(CASE  WHEN again_brush_num_temp&gt;0 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS again_brush_num,",

            "SUM( CASE WHEN date_pass_num_in &gt; 0  ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS date_pass_num, ",

            "SUM( CASE WHEN yet_finish_count_temp &gt; 0 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS yet_finish_count,",

            "SUM( CASE WHEN date_yet_finish_count_temp &gt; 0  ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS date_yet_finish_count, ",

            "SUM( CASE WHEN rebrush_count_temp &gt; 0 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS rebrush_count, ",

            "SUM( CASE WHEN yet_rebrush_count_temp &gt; 0  ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS yet_rebrush_count,",

            "SUM( CASE WHEN date_yet_rebrush_count_temp &gt; 0  ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS date_yet_rebrush_count, ",

            "SUM( CASE WHEN again_amend_num_temp &gt; 0 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS again_amend_num, ",

            "SUM( CASE WHEN again_amend_num_temp2 &gt; 0  ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS again_amend_num2,",

            "SUM( CASE WHEN yet_finish_count_temp2 &gt;=student_all_shutnum and student_all_shutnum &gt; 0 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS yet_finish_count2,",

            "SUM( CASE WHEN date_yet_finish_count_temp2 &gt;=student_all_shutnum and student_all_shutnum &gt; 0 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS date_yet_finish_count2, ",

            "SUM( CASE WHEN again_brush_num_temp2 &gt; 0 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS again_brush_num2, ",

            "SUM( CASE WHEN not_again_brush_num_temp &gt; 0  ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS not_again_brush_count, ",

            "SUM( CASE WHEN yet_again_brush_num_temp &gt; 0 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS yet_again_brush_count, ",

            "SUM( CASE WHEN date_yet_again_brush_num_temp &gt; 0 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS date_yet_again_brush_count ",

            "FROM",
            "(",
            "SELECT ",
            "td.*, ",
            "td.sourse_id AS teacher_id,",
            "tm.team_name,",
            "tm.id AS team_id,",
            "tm.pid AS team_pid ",
            "FROM",
            "xmy_erp_db.track_market AS tm",
            "LEFT JOIN xmy_erp_db.track_detail AS td ON tm.id = td.track_id AND tm.deleted = td.deleted ",
            "WHERE ",
            "tm.classify = ${classify} ",
            "AND tm.track_type = ${trackType} ",
            "AND tm.`status` = 1 ",
            "AND tm.deleted = 0 ",
            "AND tm.year_part = ${yearPart} ",
            "AND tm.quarter_num = ${quarterNum} ",
            "<when test='teamId!=null and teamId!=&apos;&apos; '>",
            "AND tm.id in(${teamId})",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
            "AND td.sourse_id = ${teacherId}",
            "</when>",
            "GROUP BY tm.id,td.sourse_id ",
            ") AS t1",
            "LEFT JOIN (",
            "SELECT",
            "school_id,",
            "year_part,",
            "quarter_num,",
            "grade_id,",
            "grade_name,",
            "teacher_id,",
            "teacher_name,",
            "class_type_id,",
            "year_class_id,",
            "student_id,",
            "lesson_num,",
            "if(brush_count=0,1,brush_count) as brush_count,",
            "add_date,",
            "SUM( CASE WHEN lowest_shutnum IS NOT NULL ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN lowest_shutnum ELSE 0 END ) AS lowest_shutnum,",

            "pass_rade, ",
            "<when test='rightNumStartDate != &apos;&apos; and rightNumEndDate != &apos;&apos;'>",
            "SUM( CASE WHEN add_date BETWEEN '${rightNumStartDate}' AND '${rightNumEndDate}' ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN right_num ELSE 0 END ) AS right_num_date_no_sum,",
            "</when>",

            "<when test='rightNumStartDate == &apos;&apos; and rightNumEndDate == &apos;&apos;'>",
            "0 AS right_num_date_no_sum,",
            "</when>",

            "SUM( CASE WHEN right_num IS NOT NULL ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            " THEN right_num ELSE 0 END ) AS right_num,",

            "SUM( CASE WHEN amend_num IS NOT NULL ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN amend_num ELSE 0 END ) AS amend_num,",

            "SUM( CASE WHEN lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS student_all_shutnum,",

            "SUM(CASE WHEN ((( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR ( brush_count &gt;= 2 AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR ( not_brush = 1 AND ( right_num + amend_num ) &gt;= lowest_shutnum )) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS yet_pass_num_temp, ",

            "SUM(CASE WHEN ((not_brush = 0 and brush_count &lt;= 1 AND ( right_num / lowest_shutnum )* 100 &lt; pass_rade) OR (not_brush = 0 and brush_count &gt;= 2 AND ( right_num + amend_num ) &lt; lowest_shutnum ) OR (( right_num / lowest_shutnum )* 100 &gt;= pass_rade  AND ( right_num + amend_num ) &lt; lowest_shutnum ) OR ( not_brush = 1 AND ( right_num + amend_num ) &lt; lowest_shutnum )) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS not_pass_num_temp, ",

            "SUM( CASE WHEN ( brush_count =0 AND ( right_num = 0 AND amend_num = 0 and lowest_shutnum is not null)",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            ") THEN 1 ELSE 0 END ) AS not_brush_num_temp,",

            "SUM( CASE WHEN (not_brush = 0 and brush_count &gt;= 1 AND brush_count &lt;= 2 AND (right_num + amend_num) &lt; lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum is not null ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            ") THEN 1 ELSE 0 END ) AS again_brush_num_temp,",

            "SUM( CASE WHEN brush_count > 0 and lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS yet_finish_count_temp,",

            "SUM( CASE WHEN ( brush_count > 0 AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            ") THEN 1 ELSE 0 END ) AS date_yet_finish_count_temp, ",

            "SUM(CASE WHEN ((( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR ( brush_count &gt;= 2 AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR (not_brush = 1 and ( right_num + amend_num ) &gt;= lowest_shutnum)) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS date_pass_num_in, ",

            "SUM(CASE WHEN ( is_first = 1 AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade ) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ) ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS rebrush_count_temp, ",

            "SUM(CASE WHEN ( is_first = 1 AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade ) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL and again_brush_id is not null) ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS yet_rebrush_count_temp, ",

            "SUM(CASE WHEN ( is_first = 1 AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade ) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL and again_brush_id is not null AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ) ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS date_yet_rebrush_count_temp, ",

            "SUM(CASE WHEN ( brush_count &gt;= 1 AND ( right_num + amend_num ) &lt; lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            ") THEN 1 ELSE 0 END ) AS again_amend_num_temp, ",

            "SUM(CASE WHEN ( brush_count = 1 AND ( right_num + amend_num ) &lt; lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL  ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            ") THEN 1 ELSE 0 END ) AS again_amend_num_temp2, ",// 需修正2（第一次刷题）

            "SUM( CASE WHEN ( brush_count = 1 AND (right_num + amend_num) &gt;= lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            ") THEN 1 ELSE 0 END ) AS yet_finish_count_temp2, ",// 已完成2（第一次刷题，正确＋修正>=应通关）

            "SUM( CASE WHEN ( brush_count = 1 AND (right_num + amend_num) &gt;= lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            ") THEN 1 ELSE 0 END ) AS date_yet_finish_count_temp2, ",// 已完成2（第一次刷题，正确＋修正>=应通关）

            "SUM(CASE WHEN (( brush_count &gt;= 1 AND (brush_count &lt; 2 OR ( right_num + amend_num &lt; lowest_shutnum )) AND (((right_num / lowest_shutnum )* 100 &lt; pass_rade ) OR (( right_num / lowest_shutnum * 100 &gt;= pass_rade ) AND ( right_num + amend_num &lt; lowest_shutnum ))) OR brush_count &gt;= 2 ) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ) ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS again_brush_num_temp2, ",// 复刷通关率，应通过

            "SUM( CASE WHEN ( ( brush_count &gt;= 1 AND (( right_num + amend_num ) &lt; lowest_shutnum OR ( right_num / lowest_shutnum )* 100 &lt; pass_rade ))) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS not_again_brush_num_temp, ",// 复刷通关率，未通关

            "SUM( CASE WHEN ( ( brush_count &gt;= 2 AND (( right_num + amend_num ) &gt;= lowest_shutnum AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade ))) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS yet_again_brush_num_temp, ",// 复刷通关率，已通关

            "SUM( CASE WHEN ( ( brush_count &gt;= 2 AND (( right_num + amend_num ) &gt;= lowest_shutnum AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade ))) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS date_yet_again_brush_num_temp ",// 复刷通关率，今日通关


            "FROM",
            "(",
            "SELECT",
            "t01.school_id,",
            "t01.year_part,",
            "t01.quarter_num,",
            "t02.course_version_id,",
            "t01.grade_id,",
            "t01.grade_name,",
            "t01.teacher_id,",
            "t01.teacher_name,",
            "t01.class_type_id,",
            "t01.year_class_id,",
            "t01.student_id,",
            "t02.task_course_num AS lesson_num,",
            "t02.not_brush,",
            "t03.is_first, ",
            "t03.is_last,",
            "t04.id AS again_brush_id,",
            "IFNULL(t03.brush_count,0) as brush_count,",
            "(CASE WHEN t03.right_num IS NOT NULL AND t03.pass_rade &gt; 0 and (t03.right_num + t03.amend_num ) &gt;= t03.lowest_shutnum AND ( t03.right_num / t03.lowest_shutnum )* 100 &gt;= t03.pass_rade THEN t03.lowest_shutnum ELSE t02.lowest_shutnum END ) AS lowest_shutnum,",
            "IFNULL( t03.right_num, 0 ) AS right_num,",
            "IFNULL( t03.amend_num, 0 ) AS amend_num,",
            "t03.add_date, ",
            "IFNULL(t03.pass_rade ,t02.pass_rade) as pass_rade ",
            "FROM",
            "(",
            "<when test= 'moldType == 1'>",
                "SELECT",
                "t1.*,",
                "t1.class_type_id_new AS class_type_id,",
                "t2.teacher_id,",
                "t2.`name` AS grade_name,",
                "sff.`name` AS teacher_name",
                "FROM",
                "xmy_erp_db.student_grade AS t1",
                "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id ",
                "INNER JOIN xmy_erp_db.staff AS sff ON sff.id = t2.teacher_id",
                "INNER JOIN per_student_account AS t3 ON t1.student_id = t3.student_id",
                "LEFT JOIN xmy_erp_db.rade_exclude_student AS t4 ON t4.classify_id = 0 AND t4.deleted = 0 AND t4.type = 2 AND t1.student_id = t4.student_id AND t1.year_part = t4.year_part AND t1.quarter_num = t4.quarter_num AND ( FIND_IN_SET( t1.subjects_id, t4.subjects_ids ) OR t4.subjects_ids IS NULL ) AND ( FIND_IN_SET( t1.school_id, t4.school_ids ) OR t4.school_ids IS NULL ) ",
                "WHERE",
                "t1.year_part = ${yearPart} ",
                "AND t1.quarter_num = ${quarterNum} ",
                "AND t1.lesson_type = 1 ",
                "AND t1.deleted = 0 ",
                "AND t1.subjects_id IN (${subjectsId}) ",
                "AND t1.is_last = 1 ",

                "<when test='include!=null and include!=&apos;&apos;'>",
                    "<when test='include == 0'>",
                        "and t4.id is null ",
                    "</when>",
                    "<when test='include == 1'>",
                        "and t4.id is not null ",
                    "</when>",
                "</when>",
                "<when test='isBeforQuarter == 0 and readingType == 1'>",
                    "AND t1.reading_status IN (1,5) ",
                "</when>",
                "<when test='isBeforQuarter == 1 and readingType == 1'>",
                    "AND t1.reading_status IN (1,5)",
                "</when>",
                "<when test='readingType == 2'>",
                    "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and use_course_count > 0)) ",
                "</when>",
                "AND t1.STATUS &lt;&gt; 3 ",
                "AND t1.deleted = 0 ",
//                "<when test='yearClassIdStr==null or yearClassIdStr==&apos;&apos; '>",
//                    "and t2.year_class_id &lt; 13",
//                "</when>",
                "<when test='name!=null and name!=&apos;&apos; '>",
                    "and sff.`name` LIKE '%${name}%'",
                "</when>",

                "and(",
                "(",
                "t2.school_id IN (${schoolIdStr})",
                "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos;'>",
                "AND t2.year_class_id IN (${yearClassIdStr})",
                "</when>",
                ")",
                "or",
                "(",
                "t2.school_id IN (${leadSchoolIds})",
                "and t2.year_class_id IN (${leadYearClassIds})",
                "and t2.teacher_id IN (${leadTeacherId})",
                ")",
                ")",

//                "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
//                    " and t2.teacher_id = ${teacherId}",
//                "</when>",
                "GROUP BY",
                "student_id ",
            "</when>",

            "<when test= 'moldType == 2'>",
                "SELECT",
                "t02.*, ",
                "t02.class_type_id_new AS class_type_id,",
                "t03.teacher_id,",
                "t03.`name` AS grade_name,",
                "staff.`name` AS teacher_name ",
                "FROM",
                "(",
                "SELECT",
                "t1.school_id,",
                "t1.old_teacher_id AS teacher_id,",
                "t1.student_id,",
                "t1.`status`,",
                "t1.reach_type,",
                "t1.old_grade_id AS grade_id,",
                "t1.subjects_id,",
                "t1.year_class_id,",
                "t1.time_start,",
                "t1.time_end,",
                "t1.course_type, ",
                "t1.lesson_num,",
                "t1.school_date,",
                "t10.year_part,",
                "t10.quarter_num ",
                "FROM",
                "xmy_erp_db.record_course AS t1 ",
                "INNER JOIN xmy_erp_db.grade AS t10 ON t1.grade_id = t10.id AND t10.is_rebrush = 0 ",
                "WHERE",
                "t1.deleted = 0 ",
                "AND t1.year_part = ${yearPart} ",
                "AND t1.`quarter` = ${quarterNum} ",
                "AND t1.`lesson_type` = 3 ",
                "AND t1.old_teacher_id IS NOT NULL ",
                "AND ((t1.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ) OR ( t1.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' AND t1.course_type = 7 )) ",

                "UNION ALL ",

                "SELECT",
                "t4.school_id,",
                "t4.teacher_id,",
                "t1.student_id,",
                "t5.`status`,",
                "t5.reach_type,",
                "t6.grade_id,",
                "t2.subjects_id,",
                "t4.year_class_id,",
                "t2.time_start,",
                "t2.time_end,",
                "1 AS course_type, ",
                "t2.lesson_num,",
                "t2.school_date, ",
                "t10.year_part,",
                "t10.quarter_num ",
                "FROM",
                "xmy_erp_db.${courseSchedulingDetailName} AS t2",
                "INNER JOIN xmy_erp_db.grade AS t10 ON t2.grade_id = t10.id AND t10.is_rebrush = 0 ",
                "INNER JOIN xmy_erp_db.student_grade AS t1 ON t2.year_part = t1.year_part ",
                "AND t2.`quarter` = t1.quarter_num ",
                "AND t2.deleted = t1.deleted ",
                "AND t2.grade_id = t1.grade_id ",
                "AND t2.lesson_type = t1.lesson_type ",
                "<when test='isBeforQuarter == 0 and readingType == 1'>",
                    "AND t1.reading_status IN (1,5) ",
                "</when>",
                "<when test='isBeforQuarter == 1 and readingType == 1'>",
                    "AND t1.reading_status IN (1,5)",
                "</when>",
                "<when test='readingType == 2'>",
                    "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and t1.use_course_count > 0)) ",
                "</when>",
                "AND t1.`status` = 1",
                "INNER JOIN xmy_erp_db.student_grade AS t6 ON t6.year_part = t1.year_part ",
                "AND t6.`quarter_num` = t1.quarter_num ",
                "AND t6.deleted = t1.deleted ",
                "AND t6.subjects_id = t1.subjects_id ",
                "AND t6.`student_id` = t1.student_id ",
                "AND t6.lesson_type = 1 ",
                "<when test='isBeforQuarter == 0 and readingType == 1'>",
                    "AND t6.reading_status IN (1,5) ",
                "</when>",
                "<when test='isBeforQuarter == 1 and readingType == 1'>",
                    "AND t6.reading_status IN (1,5)",
                "</when>",
                "<when test='readingType == 2'>",
                    "AND ((t6.reading_status IN (1,5)) or (t6.reading_status in(3,4) and t6.use_course_count > 0)) ",
                "</when>",
                "AND t6.`status` = 1",
                "and t2.end_date_time &gt;= t6.created_at",
                "LEFT JOIN xmy_erp_db.repair_course AS t3 ON t3.out_scheduling_detail_id = t2.id AND t3.deleted = 0",
                "AND t3.student_id = t1.student_id",
                "LEFT JOIN xmy_erp_db.grade AS t4 ON t6.grade_id = t4.id",
                "LEFT JOIN xmy_erp_db.record_course AS t5 ON t5.scheduling_detail_id = t2.id ",
                "AND t5.student_id = t1.student_id ",
                "AND t5.deleted = 0 ",
                "WHERE",
                "t2.year_part = ${yearPart} ",
                "AND t2.`quarter` = ${quarterNum} ",
                "AND t2.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
                "AND t2.lesson_type = 3 ",
                "AND t2.deleted = 0 ",
                "AND t2.`status` &lt;&gt; 2 ",
                "AND t3.id IS NULL ",
                "GROUP BY",
                "t2.id,",
                "t1.school_id,",
                "t1.subjects_id,",
                "t1.student_id,",
                "t1.lesson_type ",
                ") AS t01",
                "INNER JOIN xmy_erp_db.student_grade AS t02 ON t01.student_id = t02.student_id ",
                "AND t01.subjects_id = t02.subjects_id ",
                "AND t01.year_part = t02.year_part ",
                "AND t01.quarter_num = t02.quarter_num ",
                "AND t02.lesson_type = 1 ",
                "AND t02.deleted = 0 ",
                "AND t02.is_last = 1 ",
                "INNER JOIN xmy_erp_db.grade AS t03 ON t02.grade_id = t03.id ",
                "INNER JOIN xmy_erp_db.staff ON staff.id = t03.teacher_id ",
                "LEFT JOIN xmy_erp_db.rade_exclude_student AS t04 ON t04.classify_id = 0 ",
                "AND t04.deleted = 0 ",
                "AND t04.type = 2 ",
                "AND t02.student_id = t04.student_id ",
                "AND t02.year_part = t04.year_part ",
                "AND t02.quarter_num = t04.quarter_num ",
                "AND ( FIND_IN_SET( t02.subjects_id, t04.subjects_ids ) OR t04.subjects_ids IS NULL ) ",
                "AND ( FIND_IN_SET( t02.school_id, t04.school_ids ) OR t04.school_ids IS NULL ) ",
                "INNER JOIN per_student_account AS t05 ON t05.student_id = t01.student_id ",
                "LEFT JOIN xmy_erp_db.cha_study_plan AS csp ON t01.student_id = csp.student_id ",
                "AND csp.subjects_id = t01.subjects_id ",
                "AND csp.lesson_type = 3 ",
                "AND csp.`status` = 1 ",
                "AND csp.year_part = ${yearPart}",
                "AND csp.quarter_num = ${quarterNum} ",
                "AND school_date BETWEEN csp.start_task_date AND csp.end_task_date ",
                "AND DATE(csp.created_at) &lt; school_date ",
                "WHERE ",
//                "((t01.`status` = 1 AND course_type &lt;&gt; 7 ) OR ( course_type = 7 )) ",
                "t01.`status` = 1 ",
                "AND t02.`status` &lt;&gt; 3 ",
                "AND t03.year_part = ${yearPart} ",
                "AND t03.quarter_num = ${quarterNum} ",
                "AND t03.lesson_type = 1 ",
                "AND csp.student_id IS NULL",
                "AND t03.subjects_id IN (${subjectsId}) ",
//                "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
//                    "AND t03.year_class_id in(${yearClassIdStr}) ",
//                "</when>",
//                "<when test='yearClassIdStr==null or yearClassIdStr==&apos;&apos; '>",
//                    "AND t03.year_class_id &lt; 13 ",
//                "</when>",
                "<when test='include!=null and include!=&apos;&apos;'>",
                    "<when test='include == 0'>",
                        "and t04.id IS NULL  ",
                    "</when>",
                    "<when test='include == 1'>",
                        "and t04.id IS NOT NULL  ",
                    "</when>",
                "</when>",
                "<when test='isBeforQuarter == 0 and readingType == 1'>",
                    "AND t02.reading_status IN (1,5) ",
                "</when>",
                "<when test='isBeforQuarter == 1 and readingType == 1'>",
                    "AND t02.reading_status IN (1,5)",
                "</when>",
                "<when test='readingType == 2'>",
                    "AND ((t02.reading_status IN (1,5)) or (t02.reading_status in(3,4) and t02.use_course_count > 0)) ",
                "</when>",
//                "<when test='schoolIdStr!=null and schoolIdStr!=&apos;&apos; and (type == 2 || type == 4)'>",
//                    "AND t03.school_id in(${schoolIdStr}) ",
//                "</when>",
//                "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
//                    "AND t03.teacher_id in(${teacherId}) ",
//                "</when>",

                "and(",
                "(",
                "t03.school_id IN (${schoolIdStr})",
                "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos;'>",
                "AND t03.year_class_id IN (${yearClassIdStr})",
                "</when>",
                ")",
                "or",
                "(",
                "t03.school_id IN (${leadSchoolIds})",
                "and t03.year_class_id IN (${leadYearClassIds})",
                "and t03.teacher_id IN (${leadTeacherId})",
                ")",
                ")",

                "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
                    "AND t02.class_type_id_new IN (${classTypeId}) ",
                "</when>",
                "<when test='name!=null and name!=&apos;&apos; '>",
                    "AND staff.`name` LIKE '%${name}%' ",
                "</when>",
                "GROUP BY student_id",
            "</when>",

            ") AS t01",
            "LEFT JOIN ( SELECT * FROM edu_task WHERE deleted = 0 and task_category_id =${taskCategoryId} and subjects_id IN (${subjectsId}) and task_course_num BETWEEN ${lessonNumStart} and ${lessonNum} ) AS t02 ON t01.year_part = t02.year_part ",
            "AND t01.quarter_num = t02.quarter_num ",
            "AND t01.subjects_id = t02.subjects_id ",
            "AND t01.class_type_id = t02.class_type_id",
            "AND t01.year_class_id = t02.year_class_id",
            "<when test= 'inType == 2'>",
            "inner",
            "</when>",
            "<when test= 'inType != 2'>",
            "LEFT",
            "</when>",
            "JOIN (",
            "SELECT",
            "student_id,",
            "add_date,",
            "lesson_num_finish,",
            "year_class_id,",
            "course_version_id,",
            "class_type_id,",
            "year_part,",
            "quarter_num,",
            "IFNULL( lesson_num, 0 ) AS lesson_num,",
            "right_num,",
            "is_last,",
            "is_first,",
            "amend_num, ",
            "pass_rade,",
            "brush_count,",
            "lowest_shutnum",
            "FROM",
            "cha_plan ",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND quarter_num = ${quarterNum} ",
            "AND task_category_id = ${taskCategoryId} ",
            "and deleted = 0",
            ") AS t03 ON t01.year_part = t03.year_part ",
            "AND t01.quarter_num = t03.quarter_num ",
            "AND t01.student_id = t03.student_id ",
            "AND t02.year_class_id = t03.year_class_id",
            "AND t02.course_version_id = t03.course_version_id",
            "AND t02.class_type_id = t03.class_type_id ",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and t01.subjects_id IN (${subjectsId})",
            "</when>",
            "AND t02.task_course_num = t03.lesson_num",
            "<when test='radeType!=null and radeType == 1 '>",
                "<when test='isAchieve!=null and isAchieve!=&apos;&apos; and isAchieve == 0'>",
                    "and t03.is_last = 1",
                "</when>",
                "<when test='isAchieve!=null and isAchieve!=&apos;&apos; and isAchieve == 1'>",
                    "and t03.is_first = 1",
                "</when>",
            "</when>",
            "<when test='radeType!=null and (radeType == 2 or radeType == 3) '>",
                "and t03.is_first = 1",
            "</when>",

            "LEFT JOIN ( ",
            "SELECT",
            "id,",
            "student_id,",
            "add_date,",
            "lesson_num_finish,",
            "year_class_id,",
            "course_version_id,",
            "class_type_id,",
            "year_part,",
            "quarter_num,",
            "IFNULL( lesson_num, 0 ) AS lesson_num,",
            "right_num,",
            "is_last,",
            "is_first,",
            "amend_num,",
            "pass_rade,",
            "brush_count,",
            "lowest_shutnum",
            "FROM",
            "cha_plan",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND quarter_num = ${quarterNum} ",
            "AND task_category_id = ${taskCategoryId} ",
            "AND deleted = 0",
            ") AS t04 ON t04.year_part = t03.year_part ",
            "AND t04.quarter_num = t03.quarter_num ",
            "AND t04.student_id = t03.student_id ",
            "AND t04.year_class_id = t03.year_class_id ",
            "AND t04.course_version_id = t03.course_version_id ",
            "AND t04.class_type_id = t03.class_type_id ",
            "AND t04.lesson_num = t03.lesson_num ",
            "and t04.is_last = 1 ",
            "and t04.is_first = 0 ",

            ") AS t ",
            "GROUP BY student_id",
            "<if test= 'isYearClass == 1'>",
                ",year_class_id",
            "</if>",
           ") AS t02 ON t02.teacher_id = t1.teacher_id ",
            "AND ( find_in_set( t02.year_class_id, t1.year_class_id_str ) OR t1.year_class_id_str = '' ) ",
            "AND ( find_in_set( t02.school_id, t1.school_id_str ) OR t1.school_id_str = '' ) ",
            "GROUP BY team_id",
            "<if test= 'isYearClass == 1'>",
                ",year_class_id ",
            "</if>",
            "<when test='listState == 1'>",
            ",grade_id",
            "</when>",
            "<when test='teamId!=null and teamId!=&apos;&apos; '>",
            ",teacher_id",
                "HAVING teacher_id IS NOT NULL",
            "</when>",
            "<if test= 'isYearClass == 1 and (teamId == null or teamId==&apos;&apos;)'>",
//                "HAVING year_class_id IS NOT NULL",
            "</if>",
            "</script>"})
    public List<ChaPlan> getPassRadeTeamList(@Param("yearPart") String yearPart,
                                             @Param("quarterNum") String quarterNum,
                                             @Param("schoolIdStr") String schoolIdStr,
                                             @Param("yearClassIdStr") String yearClassIdStr,
                                             @Param("type") String type,
                                             @Param("lessonNumStart") String lessonNumStart,
                                             @Param("lessonNum") String lessonNum,
                                             @Param("classTypeId") String classTypeId,
                                             @Param("readingType") String readingType,
                                             @Param("lessonNow") String lessonNow,
                                             @Param("isAll") String isAll,
                                             @Param("passDate") String passDate,
                                             @Param("passDateStart") String passDateStart,
                                             @Param("passDateEnd") String passDateEnd,
                                             @Param("subjectsId") String subjectsId,
                                             @Param("isBeforQuarter") String isBeforQuarter,
                                             @Param("readingStatusStr") String readingStatusStr,
                                             @Param("rightNumStartDate") String rightNumStartDate,
                                             @Param("rightNumEndDate") String rightNumEndDate,
                                             @Param("trackId") String trackId,
                                             @Param("isYearClass") Integer isYearClass,
                                             @Param("radeType") String radeType,
                                             @Param("listState") String listState,
                                             @Param("teacherId") String teacherId,
                                             @Param("name") String name,
                                             @Param("classify") String classify,
                                             @Param("trackType") String trackType,
                                             @Param("teamId") String teamId,
                                             @Param("include") String include,
                                             @Param("inType") String inType,
                                             @Param("taskCategoryId") Integer taskCategoryId,
                                             @Param("isAchieve") String isAchieve,
                                             @Param("moldType") String moldType, // 1正常通关率、2到勤通关率
                                             @Param("courseSchedulingDetailName") String courseSchedulingDetailName,
                                             @Param("leadSchoolIds") String leadSchoolIds,
                                             @Param("leadSubjectsIds") String leadSubjectsIds,
                                             @Param("leadYearClassIds") String leadYearClassIds,
                                             @Param("leadTeacherId") Long leadTeacherId
    );


    /**
     * 已过刷题排班和未到刷题排班战队
     * @return
     */
    @Select({"<script>",

            "<when test= 'examSchedulingtType == 1'>",
            "WITH wi_tb01 AS (",
                "SELECT",
                "rc.student_id",
                "FROM",
                "xmy_erp_db.record_course AS rc",
               "  INNER JOIN xmy_erp_db.student s ON s.id = rc.student_id",
                "where",
                "rc.subjects_id = ${subjectsId}",
               " and rc.year_part = ${yearPart}",
                "AND rc.quarter = ${quarterNum}",
               " AND rc.lesson_type = 3 ",
                "AND rc.deleted = 0",
                "and rc.course_type &lt;&gt; 7",
                "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
                "and s.year_class_id in(${yearClassIdStr})",
                "</when>",
               " AND rc.school_date BETWEEN #{schoolDateStart} AND #{schoolDateEnd}",
            "   ) ",
            "</when>",
            "<when test= 'examSchedulingtType == 2'>",
               " WITH wi_tb01 AS (",
              "  SELECT",
                "t1.student_id",
                "FROM",
                "xmy_erp_db.student_grade AS t1",
                "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id",
                "INNER JOIN xmy_erp_db.course_scheduling_detail AS t3 ON t1.grade_id = t3.grade_id and t3.deleted = 0",
                "INNER JOIN xmy_erp_db.student s ON s.id = t1.student_id",
                "WHERE",
                "t1.year_part = ${yearPart}",
                "AND t1.quarter_num = ${quarterNum}",
                "and t1.deleted = 0",
                "AND t2.lesson_type = 3",
                "AND t1.reading_status = 1",
                "AND t1.subjects_id = ${subjectsId}",
                    "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
                    "and s.year_class_id in(${yearClassIdStr})",
                    "</when>",
                "AND t3.school_date BETWEEN #{schoolDateStart} AND #{schoolDateEnd}",
//                "AND '2025-04-20'",
                "GROUP BY",
                "t1.student_id",
                 ")",
            "</when>",


            "SELECT",
            "t02.*,team_name,team_id,team_pid,",
            "SUM( lowest_shutnum ) AS lowest_shutnum_all,",
            "SUM( right_num ) AS right_num_all,",
            "<when test='rightNumStartDate != &apos;&apos; and rightNumEndDate != &apos;&apos;'>",
            "SUM( right_num_date_no_sum ) AS right_num_date,",
            "</when>",
            "<when test='rightNumStartDate == &apos;&apos; and rightNumEndDate == &apos;&apos;'>",
            "0 AS right_num_date,",
            "</when>",
            "SUM( amend_num ) AS amend_num_all,",
            "SUM( lowest_shutnum - right_num ) AS error_num_all,",

            "SUM( CASE WHEN (lowest_shutnum &lt;&gt; 0 and lowest_shutnum is not null",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            ") THEN 1 ELSE 0 END ) AS show_pass_num,",

            "SUM( CASE WHEN yet_pass_num_temp &gt;=student_all_shutnum and student_all_shutnum &gt; 0 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS yet_pass_num,",

            "SUM( CASE WHEN not_pass_num_temp &gt;0 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS not_pass_num,",

            "SUM( CASE WHEN not_brush_num_temp &gt;0 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS not_brush_num,",

            "SUM(CASE  WHEN again_brush_num_temp&gt;0 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS again_brush_num,",

            "SUM( CASE WHEN date_pass_num_in &gt; 0  ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS date_pass_num, ",

            "SUM( CASE WHEN yet_finish_count_temp &gt; 0 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS yet_finish_count,",

            "SUM( CASE WHEN date_yet_finish_count_temp &gt; 0  ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS date_yet_finish_count, ",

            "SUM( CASE WHEN rebrush_count_temp &gt; 0 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS rebrush_count, ",

            "SUM( CASE WHEN yet_rebrush_count_temp &gt; 0  ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS yet_rebrush_count,",

            "SUM( CASE WHEN date_yet_rebrush_count_temp &gt; 0  ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS date_yet_rebrush_count, ",

            "SUM( CASE WHEN again_amend_num_temp &gt; 0 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS again_amend_num, ",

            "SUM( CASE WHEN again_amend_num_temp2 &gt; 0  ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS again_amend_num2,",

            "SUM( CASE WHEN yet_finish_count_temp2 &gt;=student_all_shutnum and student_all_shutnum &gt; 0 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS yet_finish_count2,",

            "SUM( CASE WHEN date_yet_finish_count_temp2 &gt;=student_all_shutnum and student_all_shutnum &gt; 0 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS date_yet_finish_count2, ",

            "SUM( CASE WHEN again_brush_num_temp2 &gt; 0 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS again_brush_num2, ",

            "SUM( CASE WHEN not_again_brush_num_temp &gt; 0  ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS not_again_brush_count, ",

            "SUM( CASE WHEN yet_again_brush_num_temp &gt; 0 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS yet_again_brush_count, ",

            "SUM( CASE WHEN date_yet_again_brush_num_temp &gt; 0 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS date_yet_again_brush_count ",

            "FROM",
            "(",
            "SELECT ",
            "td.*, ",
            "td.sourse_id AS teacher_id,",
            "tm.team_name,",
            "tm.id AS team_id,",
            "tm.pid AS team_pid ",
            "FROM",
            "xmy_erp_db.track_market AS tm",
            "LEFT JOIN xmy_erp_db.track_detail AS td ON tm.id = td.track_id AND tm.deleted = td.deleted ",
            "WHERE ",
            "tm.classify = ${classify} ",
            "AND tm.track_type = ${trackType} ",
            "AND tm.`status` = 1 ",
            "AND tm.deleted = 0 ",
            "AND tm.year_part = ${yearPart} ",
            "AND tm.quarter_num = ${quarterNum} ",
            "<when test='teamId!=null and teamId!=&apos;&apos; '>",
            "AND tm.id in(${teamId})",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
            "AND td.sourse_id = ${teacherId}",
            "</when>",
            "GROUP BY tm.id,td.sourse_id ",
            ") AS t1",
            "LEFT JOIN (",
            "SELECT",
            "school_id,",
            "year_part,",
            "quarter_num,",
            "grade_id,",
            "grade_name,",
            "teacher_id,",
            "teacher_name,",
            "class_type_id,",
            "year_class_id,",
            "student_id,",
            "lesson_num,",
            "if(brush_count=0,1,brush_count) as brush_count,",
            "add_date,",
            "SUM( CASE WHEN lowest_shutnum IS NOT NULL ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN lowest_shutnum ELSE 0 END ) AS lowest_shutnum,",

            "pass_rade, ",
            "<when test='rightNumStartDate != &apos;&apos; and rightNumEndDate != &apos;&apos;'>",
            "SUM( CASE WHEN add_date BETWEEN '${rightNumStartDate}' AND '${rightNumEndDate}' ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN right_num ELSE 0 END ) AS right_num_date_no_sum,",
            "</when>",

            "<when test='rightNumStartDate == &apos;&apos; and rightNumEndDate == &apos;&apos;'>",
            "0 AS right_num_date_no_sum,",
            "</when>",

            "SUM( CASE WHEN right_num IS NOT NULL ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            " THEN right_num ELSE 0 END ) AS right_num,",

            "SUM( CASE WHEN amend_num IS NOT NULL ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN amend_num ELSE 0 END ) AS amend_num,",

            "SUM( CASE WHEN lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS student_all_shutnum,",

            "SUM(CASE WHEN ((( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR ( brush_count &gt;= 2 AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR ( not_brush = 1 AND ( right_num + amend_num ) &gt;= lowest_shutnum )) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS yet_pass_num_temp, ",

            "SUM(CASE WHEN ((not_brush = 0 and brush_count &lt;= 1 AND ( right_num / lowest_shutnum )* 100 &lt; pass_rade) OR (not_brush = 0 and brush_count &gt;= 2 AND ( right_num + amend_num ) &lt; lowest_shutnum ) OR (( right_num / lowest_shutnum )* 100 &gt;= pass_rade  AND ( right_num + amend_num ) &lt; lowest_shutnum ) OR ( not_brush = 1 AND ( right_num + amend_num ) &lt; lowest_shutnum )) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS not_pass_num_temp, ",

            "SUM( CASE WHEN ( brush_count =0 AND ( right_num = 0 AND amend_num = 0 and lowest_shutnum is not null)",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            ") THEN 1 ELSE 0 END ) AS not_brush_num_temp,",

            "SUM( CASE WHEN (not_brush = 0 and brush_count &gt;= 1 AND brush_count &lt;= 2 AND (right_num + amend_num) &lt; lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum is not null ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            ") THEN 1 ELSE 0 END ) AS again_brush_num_temp,",

            "SUM( CASE WHEN brush_count > 0 and lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS yet_finish_count_temp,",

            "SUM( CASE WHEN ( brush_count > 0 AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            ") THEN 1 ELSE 0 END ) AS date_yet_finish_count_temp, ",

            "SUM(CASE WHEN ((( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR ( brush_count &gt;= 2 AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR (not_brush = 1 and ( right_num + amend_num ) &gt;= lowest_shutnum)) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS date_pass_num_in, ",

            "SUM(CASE WHEN ( is_first = 1 AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade ) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ) ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS rebrush_count_temp, ",

            "SUM(CASE WHEN ( is_first = 1 AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade ) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL and again_brush_id is not null) ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS yet_rebrush_count_temp, ",

            "SUM(CASE WHEN ( is_first = 1 AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade ) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL and again_brush_id is not null AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ) ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS date_yet_rebrush_count_temp, ",

            "SUM(CASE WHEN ( brush_count &gt;= 1 AND ( right_num + amend_num ) &lt; lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            ") THEN 1 ELSE 0 END ) AS again_amend_num_temp, ",

            "SUM(CASE WHEN ( brush_count = 1 AND ( right_num + amend_num ) &lt; lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL  ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            ") THEN 1 ELSE 0 END ) AS again_amend_num_temp2, ",// 需修正2（第一次刷题）

            "SUM( CASE WHEN ( brush_count = 1 AND (right_num + amend_num) &gt;= lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            ") THEN 1 ELSE 0 END ) AS yet_finish_count_temp2, ",// 已完成2（第一次刷题，正确＋修正>=应通关）

            "SUM( CASE WHEN ( brush_count = 1 AND (right_num + amend_num) &gt;= lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            ") THEN 1 ELSE 0 END ) AS date_yet_finish_count_temp2, ",// 已完成2（第一次刷题，正确＋修正>=应通关）

            "SUM(CASE WHEN (( brush_count &gt;= 1 AND (brush_count &lt; 2 OR ( right_num + amend_num &lt; lowest_shutnum )) AND (((right_num / lowest_shutnum )* 100 &lt; pass_rade ) OR (( right_num / lowest_shutnum * 100 &gt;= pass_rade ) AND ( right_num + amend_num &lt; lowest_shutnum ))) OR brush_count &gt;= 2 ) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ) ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS again_brush_num_temp2, ",// 复刷通关率，应通过

            "SUM( CASE WHEN ( ( brush_count &gt;= 1 AND (( right_num + amend_num ) &lt; lowest_shutnum OR ( right_num / lowest_shutnum )* 100 &lt; pass_rade ))) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS not_again_brush_num_temp, ",// 复刷通关率，未通关

            "SUM( CASE WHEN ( ( brush_count &gt;= 2 AND (( right_num + amend_num ) &gt;= lowest_shutnum AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade ))) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS yet_again_brush_num_temp, ",// 复刷通关率，已通关

            "SUM( CASE WHEN ( ( brush_count &gt;= 2 AND (( right_num + amend_num ) &gt;= lowest_shutnum AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade ))) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS date_yet_again_brush_num_temp ",// 复刷通关率，今日通关

            "FROM",
            "(",
            "SELECT",
            "t01.school_id,",
            "t01.year_part,",
            "t01.quarter_num,",
            "t02.course_version_id,",
            "t01.grade_id,",
            "t01.grade_name,",
            "t01.teacher_id,",
            "t01.teacher_name,",
            "t01.class_type_id,",
            "t01.year_class_id,",
            "t01.student_id,",
            "t02.task_course_num AS lesson_num,",
            "t02.not_brush,",
            "t03.is_first, ",
            "t03.is_last,",
            "t04.id AS again_brush_id,",
            "IFNULL(t03.brush_count,0) as brush_count,",
            "(CASE WHEN t03.right_num IS NOT NULL AND t03.pass_rade &gt; 0 and (t03.right_num + t03.amend_num ) &gt;= t03.lowest_shutnum AND ( t03.right_num / t03.lowest_shutnum )* 100 &gt;= t03.pass_rade THEN t03.lowest_shutnum ELSE t02.lowest_shutnum END ) AS lowest_shutnum,",
            "IFNULL( t03.right_num, 0 ) AS right_num,",
            "IFNULL( t03.amend_num, 0 ) AS amend_num,",
            "t03.add_date, ",
            "IFNULL(t03.pass_rade ,t02.pass_rade) as pass_rade ",
            "FROM",
            "(",
            "<when test= 'moldType == 1'>",
            "SELECT",
            "t1.*,",
            "t1.class_type_id_new AS class_type_id,",
            "t2.teacher_id,",
            "t2.`name` AS grade_name,",
            "sff.`name` AS teacher_name",
            "FROM",
            "xmy_erp_db.student_grade AS t1",
            "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id ",
            "INNER JOIN xmy_erp_db.staff AS sff ON sff.id = t2.teacher_id",

            //已过刷题排班和未到刷题排班
            "INNER JOIN wi_tb01 on t1.student_id = wi_tb01.student_id",

            "INNER JOIN per_student_account AS t3 ON t1.student_id = t3.student_id",
            "LEFT JOIN xmy_erp_db.rade_exclude_student AS t4 ON t4.classify_id = 0 AND t4.deleted = 0 AND t4.type = 2 AND t1.student_id = t4.student_id AND t1.year_part = t4.year_part AND t1.quarter_num = t4.quarter_num AND ( FIND_IN_SET( t1.subjects_id, t4.subjects_ids ) OR t4.subjects_ids IS NULL ) AND ( FIND_IN_SET( t1.school_id, t4.school_ids ) OR t4.school_ids IS NULL ) ",
            "WHERE",
            "t1.year_part = ${yearPart} ",
            "AND t1.quarter_num = ${quarterNum} ",
            "AND t1.lesson_type = 1 ",
            "AND t1.deleted = 0 ",
            "AND t1.subjects_id IN (${subjectsId}) ",
            "AND t1.is_last = 1 ",

            "<when test='include!=null and include!=&apos;&apos;'>",
            "<when test='include == 0'>",
            "and t4.id is null ",
            "</when>",
            "<when test='include == 1'>",
            "and t4.id is not null ",
            "</when>",
            "</when>",
            "<when test='isBeforQuarter == 0 and readingType == 1'>",
            "AND t1.reading_status IN (1,5) ",
            "</when>",
            "<when test='isBeforQuarter == 1 and readingType == 1'>",
            "AND t1.reading_status IN (1,5)",
            "</when>",
            "<when test='readingType == 2'>",
            "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and use_course_count > 0)) ",
            "</when>",
            "AND t1.STATUS &lt;&gt; 3 ",
            "AND t1.deleted = 0 ",
            "<when test='yearClassIdStr==null or yearClassIdStr==&apos;&apos; '>",
            "and t2.year_class_id &lt; 13",
            "</when>",
            "<when test='name!=null and name!=&apos;&apos; '>",
            "and sff.`name` LIKE '%${name}%'",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
            " and t2.teacher_id = ${teacherId}",
            "</when>",
            "GROUP BY",
            "student_id ",
            "</when>",

            "<when test= 'moldType == 2'>",
            "SELECT",
            "t02.*, ",
            "t02.class_type_id_new AS class_type_id,",
            "t03.teacher_id,",
            "t03.`name` AS grade_name,",
            "staff.`name` AS teacher_name ",
            "FROM",
            "(",
            "SELECT",
            "t1.school_id,",
            "t1.old_teacher_id AS teacher_id,",
            "t1.student_id,",
            "t1.`status`,",
            "t1.reach_type,",
            "t1.old_grade_id AS grade_id,",
            "t1.subjects_id,",
            "t1.year_class_id,",
            "t1.time_start,",
            "t1.time_end,",
            "t1.course_type, ",
            "t1.lesson_num,",
            "t1.school_date,",
            "t10.year_part,",
            "t10.quarter_num ",
            "FROM",
            "xmy_erp_db.record_course AS t1 ",
            "INNER JOIN xmy_erp_db.grade AS t10 ON t1.grade_id = t10.id AND t10.is_rebrush = 0 ",
            "WHERE",
            "t1.deleted = 0 ",
            "AND t1.year_part = ${yearPart} ",
            "AND t1.`quarter` = ${quarterNum} ",
            "AND t1.`lesson_type` = 3 ",
            "AND t1.old_teacher_id IS NOT NULL ",
            "AND ((t1.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ) OR ( t1.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' AND t1.course_type = 7 )) ",

            "UNION ALL ",

            "SELECT",
            "t4.school_id,",
            "t4.teacher_id,",
            "t1.student_id,",
            "t5.`status`,",
            "t5.reach_type,",
            "t6.grade_id,",
            "t2.subjects_id,",
            "t4.year_class_id,",
            "t2.time_start,",
            "t2.time_end,",
            "1 AS course_type, ",
            "t2.lesson_num,",
            "t2.school_date, ",
            "t10.year_part,",
            "t10.quarter_num ",
            "FROM",
            "xmy_erp_db.${courseSchedulingDetailName} AS t2",
            "INNER JOIN xmy_erp_db.grade AS t10 ON t2.grade_id = t10.id AND t10.is_rebrush = 0 ",
            "INNER JOIN xmy_erp_db.student_grade AS t1 ON t2.year_part = t1.year_part ",
            "AND t2.`quarter` = t1.quarter_num ",
            "AND t2.deleted = t1.deleted ",
            "AND t2.grade_id = t1.grade_id ",
            "AND t2.lesson_type = t1.lesson_type ",
            "<when test='isBeforQuarter == 0 and readingType == 1'>",
            "AND t1.reading_status IN (1,5) ",
            "</when>",
            "<when test='isBeforQuarter == 1 and readingType == 1'>",
            "AND t1.reading_status IN (1,5)",
            "</when>",
            "<when test='readingType == 2'>",
            "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and t1.use_course_count > 0)) ",
            "</when>",
            "AND t1.`status` = 1",
            "INNER JOIN xmy_erp_db.student_grade AS t6 ON t6.year_part = t1.year_part ",
            "AND t6.`quarter_num` = t1.quarter_num ",
            "AND t6.deleted = t1.deleted ",
            "AND t6.subjects_id = t1.subjects_id ",
            "AND t6.`student_id` = t1.student_id ",
            "AND t6.lesson_type = 1 ",
            "<when test='isBeforQuarter == 0 and readingType == 1'>",
            "AND t6.reading_status IN (1,5) ",
            "</when>",
            "<when test='isBeforQuarter == 1 and readingType == 1'>",
            "AND t6.reading_status IN (1,5)",
            "</when>",
            "<when test='readingType == 2'>",
            "AND ((t6.reading_status IN (1,5)) or (t6.reading_status in(3,4) and t6.use_course_count > 0)) ",
            "</when>",
            "AND t6.`status` = 1",
            "and t2.end_date_time &gt;= t6.created_at",
            "LEFT JOIN xmy_erp_db.repair_course AS t3 ON t3.out_scheduling_detail_id = t2.id AND t3.deleted = 0",
            "AND t3.student_id = t1.student_id",
            "LEFT JOIN xmy_erp_db.grade AS t4 ON t6.grade_id = t4.id",
            "LEFT JOIN xmy_erp_db.record_course AS t5 ON t5.scheduling_detail_id = t2.id ",
            "AND t5.student_id = t1.student_id ",
            "AND t5.deleted = 0 ",
            "WHERE",
            "t2.year_part = ${yearPart} ",
            "AND t2.`quarter` = ${quarterNum} ",
            "AND t2.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
            "AND t2.lesson_type = 3 ",
            "AND t2.deleted = 0 ",
            "AND t2.`status` &lt;&gt; 2 ",
            "AND t3.id IS NULL ",
            "GROUP BY",
            "t2.id,",
            "t1.school_id,",
            "t1.subjects_id,",
            "t1.student_id,",
            "t1.lesson_type ",
            ") AS t01",
            "INNER JOIN xmy_erp_db.student_grade AS t02 ON t01.student_id = t02.student_id ",
            "AND t01.subjects_id = t02.subjects_id ",
            "AND t01.year_part = t02.year_part ",
            "AND t01.quarter_num = t02.quarter_num ",
            "AND t02.lesson_type = 1 ",
            "AND t02.deleted = 0 ",
            "AND t02.is_last = 1 ",
            "INNER JOIN xmy_erp_db.grade AS t03 ON t02.grade_id = t03.id ",
            "INNER JOIN xmy_erp_db.staff ON staff.id = t03.teacher_id ",
            "LEFT JOIN xmy_erp_db.rade_exclude_student AS t04 ON t04.classify_id = 0 ",
            "AND t04.deleted = 0 ",
            "AND t04.type = 2 ",
            "AND t02.student_id = t04.student_id ",
            "AND t02.year_part = t04.year_part ",
            "AND t02.quarter_num = t04.quarter_num ",
            "AND ( FIND_IN_SET( t02.subjects_id, t04.subjects_ids ) OR t04.subjects_ids IS NULL ) ",
            "AND ( FIND_IN_SET( t02.school_id, t04.school_ids ) OR t04.school_ids IS NULL ) ",
            "INNER JOIN per_student_account AS t05 ON t05.student_id = t01.student_id ",
            "LEFT JOIN xmy_erp_db.cha_study_plan AS csp ON t01.student_id = csp.student_id ",
            "AND csp.subjects_id = t01.subjects_id ",
            "AND csp.lesson_type = 3 ",
            "AND csp.`status` = 1 ",
            "AND csp.year_part = ${yearPart}",
            "AND csp.quarter_num = ${quarterNum} ",
            "AND school_date BETWEEN csp.start_task_date AND csp.end_task_date ",
            "AND DATE(csp.created_at) &lt; school_date ",
            "WHERE ",
//                "((t01.`status` = 1 AND course_type &lt;&gt; 7 ) OR ( course_type = 7 )) ",
            "t01.`status` = 1 ",
            "AND t02.`status` &lt;&gt; 3 ",
            "AND t03.year_part = ${yearPart} ",
            "AND t03.quarter_num = ${quarterNum} ",
            "AND t03.lesson_type = 1 ",
            "AND csp.student_id IS NULL",
            "AND t03.subjects_id IN (${subjectsId}) ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "AND t03.year_class_id in(${yearClassIdStr}) ",
            "</when>",
            "<when test='yearClassIdStr==null or yearClassIdStr==&apos;&apos; '>",
            "AND t03.year_class_id &lt; 13 ",
            "</when>",
            "<when test='include!=null and include!=&apos;&apos;'>",
            "<when test='include == 0'>",
            "and t04.id IS NULL  ",
            "</when>",
            "<when test='include == 1'>",
            "and t04.id IS NOT NULL  ",
            "</when>",
            "</when>",
            "<when test='isBeforQuarter == 0 and readingType == 1'>",
            "AND t02.reading_status IN (1,5) ",
            "</when>",
            "<when test='isBeforQuarter == 1 and readingType == 1'>",
            "AND t02.reading_status IN (1,5)",
            "</when>",
            "<when test='readingType == 2'>",
            "AND ((t02.reading_status IN (1,5)) or (t02.reading_status in(3,4) and t02.use_course_count > 0)) ",
            "</when>",
            "<when test='schoolIdStr!=null and schoolIdStr!=&apos;&apos; and (type == 2 || type == 4)'>",
            "AND t03.school_id in(${schoolIdStr}) ",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
            "AND t03.teacher_id in(${teacherId}) ",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "AND t02.class_type_id_new IN (${classTypeId}) ",
            "</when>",
            "<when test='name!=null and name!=&apos;&apos; '>",
            "AND staff.`name` LIKE '%${name}%' ",
            "</when>",
            "GROUP BY student_id",
            "</when>",

            ") AS t01",
            "LEFT JOIN ( SELECT * FROM edu_task WHERE deleted = 0 and task_category_id =${taskCategoryId} and subjects_id IN (${subjectsId}) and task_course_num BETWEEN ${lessonNumStart} and ${lessonNum} ) AS t02 ON t01.year_part = t02.year_part ",
            "AND t01.quarter_num = t02.quarter_num ",
            "AND t01.subjects_id = t02.subjects_id ",
            "AND t01.class_type_id = t02.class_type_id",
            "AND t01.year_class_id = t02.year_class_id",
            "<when test= 'inType == 2'>",
            "inner",
            "</when>",
            "<when test= 'inType != 2'>",
            "LEFT",
            "</when>",
            "JOIN (",
            "SELECT",
            "student_id,",
            "add_date,",
            "lesson_num_finish,",
            "year_class_id,",
            "course_version_id,",
            "class_type_id,",
            "year_part,",
            "quarter_num,",
            "IFNULL( lesson_num, 0 ) AS lesson_num,",
            "right_num,",
            "is_last,",
            "is_first,",
            "amend_num, ",
            "pass_rade,",
            "brush_count,",
            "lowest_shutnum",
            "FROM",
            "cha_plan ",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND quarter_num = ${quarterNum} ",
            "AND task_category_id = ${taskCategoryId} ",
            "and deleted = 0",
            ") AS t03 ON t01.year_part = t03.year_part ",
            "AND t01.quarter_num = t03.quarter_num ",
            "AND t01.student_id = t03.student_id ",
            "AND t02.year_class_id = t03.year_class_id",
            "AND t02.course_version_id = t03.course_version_id",
            "AND t02.class_type_id = t03.class_type_id ",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and t01.subjects_id IN (${subjectsId})",
            "</when>",
            "AND t02.task_course_num = t03.lesson_num",
            "<when test='radeType!=null and radeType == 1 '>",
            "<when test='isAchieve!=null and isAchieve!=&apos;&apos; and isAchieve == 0'>",
            "and t03.is_last = 1",
            "</when>",
            "<when test='isAchieve!=null and isAchieve!=&apos;&apos; and isAchieve == 1'>",
            "and t03.is_first = 1",
            "</when>",
            "</when>",
            "<when test='radeType!=null and (radeType == 2 or radeType == 3) '>",
            "and t03.is_first = 1",
            "</when>",

            "LEFT JOIN ( ",
            "SELECT",
            "id,",
            "student_id,",
            "add_date,",
            "lesson_num_finish,",
            "year_class_id,",
            "course_version_id,",
            "class_type_id,",
            "year_part,",
            "quarter_num,",
            "IFNULL( lesson_num, 0 ) AS lesson_num,",
            "right_num,",
            "is_last,",
            "is_first,",
            "amend_num,",
            "pass_rade,",
            "brush_count,",
            "lowest_shutnum",
            "FROM",
            "cha_plan",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND quarter_num = ${quarterNum} ",
            "AND task_category_id = ${taskCategoryId} ",
            "AND deleted = 0",
            ") AS t04 ON t04.year_part = t03.year_part ",
            "AND t04.quarter_num = t03.quarter_num ",
            "AND t04.student_id = t03.student_id ",
            "AND t04.year_class_id = t03.year_class_id ",
            "AND t04.course_version_id = t03.course_version_id ",
            "AND t04.class_type_id = t03.class_type_id ",
            "AND t04.lesson_num = t03.lesson_num ",
            "and t04.is_last = 1 ",
            "and t04.is_first = 0 ",

            ") AS t ",
            "GROUP BY student_id",
            "<if test= 'isYearClass == 1'>",
            ",year_class_id",
            "</if>",
            ") AS t02 ON t02.teacher_id = t1.teacher_id ",
            "AND ( find_in_set( t02.year_class_id, t1.year_class_id_str ) OR t1.year_class_id_str = '' ) ",
            "AND ( find_in_set( t02.school_id, t1.school_id_str ) OR t1.school_id_str = '' ) ",
            "GROUP BY team_id",
            "<if test= 'isYearClass == 1'>",
            ",year_class_id ",
            "</if>",
            "<when test='listState == 1'>",
            ",grade_id",
            "</when>",
            "<when test='teamId!=null and teamId!=&apos;&apos; '>",
            ",teacher_id",
            "HAVING teacher_id IS NOT NULL",
            "</when>",
            "<if test= 'isYearClass == 1 and (teamId == null or teamId==&apos;&apos;)'>",
//                "HAVING year_class_id IS NOT NULL",
            "</if>",
            "</script>"})
    public List<ChaPlan> getPassedBrushiTeamDate(@Param("yearPart") String yearPart,
                                             @Param("quarterNum") String quarterNum,
                                             @Param("schoolIdStr") String schoolIdStr,
                                             @Param("yearClassIdStr") String yearClassIdStr,
                                             @Param("type") String type,
                                             @Param("lessonNumStart") String lessonNumStart,
                                             @Param("lessonNum") String lessonNum,
                                             @Param("classTypeId") String classTypeId,
                                             @Param("readingType") String readingType,
                                             @Param("lessonNow") String lessonNow,
                                             @Param("isAll") String isAll,
                                             @Param("passDate") String passDate,
                                             @Param("passDateStart") String passDateStart,
                                             @Param("passDateEnd") String passDateEnd,
                                             @Param("subjectsId") String subjectsId,
                                             @Param("isBeforQuarter") String isBeforQuarter,
                                             @Param("readingStatusStr") String readingStatusStr,
                                             @Param("rightNumStartDate") String rightNumStartDate,
                                             @Param("rightNumEndDate") String rightNumEndDate,
                                             @Param("trackId") String trackId,
                                             @Param("isYearClass") Integer isYearClass,
                                             @Param("radeType") String radeType,
                                             @Param("listState") String listState,
                                             @Param("teacherId") String teacherId,
                                             @Param("name") String name,
                                             @Param("classify") String classify,
                                             @Param("trackType") String trackType,
                                             @Param("teamId") String teamId,
                                             @Param("include") String include,
                                             @Param("inType") String inType,
                                             @Param("taskCategoryId") Integer taskCategoryId,
                                             @Param("isAchieve") String isAchieve,
                                             @Param("moldType") String moldType, // 1正常通关率、2到勤通关率
                                             @Param("courseSchedulingDetailName") String courseSchedulingDetailName,
                                             @Param("schoolDateStart") String schoolDateStart,
                                             @Param("schoolDateEnd") String schoolDateEnd,
                                             @Param("examSchedulingtType") String examSchedulingtType
                                             );

    @Select({"<script>",
            "WITH tb_school_time_01 AS (",
            "SELECT *,",
            "MAX( CASE WHEN subjects_id = 1 THEN school_time END ) AS en_school_time,",
            "MAX( CASE WHEN subjects_id = 2 THEN school_time END ) AS ma_school_time,",
            "MAX( CASE WHEN subjects_id = 3 THEN school_time END ) AS ph_school_time ",
            "FROM (",
            "SELECT *, ",
            "GROUP_CONCAT( time_start_end ORDER BY t.week_dates ) AS school_time ",
            "FROM (",
            "SELECT t1.id,t1.year_part,t1.quarter_num,t1.student_id,t1.subjects_id,t2.week_dates,",
            "CONCAT(getWeekdayName ( t2.week_dates ), '', t2.time_start, ' - ', t2.time_end ) AS time_start_end ",
            "FROM ",
            "xmy_erp_db.student_grade AS t1 ",
            "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id ",
            "WHERE ",
            "t1.year_part = ${yearPart} ",
            "AND t1.quarter_num = ${quarterNum} ",
            "AND t1.lesson_type &lt;&gt; 1",
            "AND t1.deleted = 0 ",
            "AND t1.`status` = 1 ",
            "<if test= 'readingType == 1'>",
            "<if test= 'isBeforQuarter == 0'>",
            "AND t1.reading_status = 1 ",
            "</if>",
            "<if test= 'isBeforQuarter == 1'>",
            "AND t1.reading_status IN (1,3,4,5,6 ) ",
            "</if>",
            "</if>",
            "<if test= 'readingType == 2'>",
            "AND t1.reading_status IN (1,3,4,5,6 ) ",
            "</if>",
            "GROUP BY t1.grade_id,t1.student_id,t1.subjects_id ",
            ") AS t ",
            "GROUP BY student_id,subjects_id ",
            ") AS t ",
            "GROUP BY student_id",
            ")",

            "SELECT",
            "*,if(brush_count_temp = 0,1,brush_count_temp) as brush_count ",
            "<when test='listState != 1 and listState != 2'>",
                ",pass_date_time1 AS pass_date_time ",
            "</when>",
            "<when test='listState == 1 or listState == 2'>",
                ",MAX( pass_date_time1 ) AS pass_date_time ",
            "</when>",
            "<when test='listState == 2'>",// 正确率学员详情，为了不影响其他的合并课次数据，所以改成了2，为1的不适用于正确率
                ",GROUP_CONCAT( lesson_num ) AS LessonNumNot,",
                "SUM(lowest_shutnum) AS lowestShutnumAll,",
                "SUM(right_num) AS rightNumAll,",
                "SUM(amend_num) AS amendNumAll",
            "</when>",
            "FROM",
            "(",
            "SELECT",
            "t01.id,",
            "t01.subjects_id,",
            "t01.school_id,",
            "t01.year_part,",
            "t01.quarter_num,",
            "t02.course_version_id,",
            "t01.grade_id,",
            "t01.teacher_id,",
            "t01.class_type_id,",
            "t01.year_class_id,",
            "t01.linkman_phone,",
            "t01.student_id,",
            "t03.is_first,",
            "t03.is_last,",
            "t04.id AS again_brush_id, ",
            "t02.task_course_num AS lesson_num,",
            "t02.not_brush,",
            "t07.en_school_time,",
            "t07.ma_school_time,",
            "t07.ph_school_time,",
            "IFNULL(t03.brush_count,0) as brush_count_temp,",
            "IFNULL( t03.brush_count &gt; 0 AND t03.lowest_shutnum &lt;&gt; 0 AND t03.lowest_shutnum IS NOT NULL, 1) AS yet_finish_count, ",// 已完成
            "IFNULL( t03.is_first = 1 AND (( t03.right_num / t03.lowest_shutnum )* 100 &lt; t03.pass_rade ) AND t03.lowest_shutnum &lt;&gt; 0 AND t03.lowest_shutnum IS NOT NULL AND t03.t04.id IS NOT NULL , 1 ) AS yet_rebrush_count,",// 已复刷
            "IFNULL( t03.pass_rade,t02.pass_rade) as pass_rade, ",
            "(CASE WHEN t03.right_num IS NOT NULL AND t03.pass_rade &gt; 0 and (t03.right_num + t03.amend_num ) &gt;= t03.lowest_shutnum AND ( t03.right_num / t03.lowest_shutnum )* 100 &gt;= t03.pass_rade THEN t03.lowest_shutnum ELSE t02.lowest_shutnum END ) AS lowest_shutnum,",
            "IFNULL( t03.right_num, 0 ) AS right_num,",
            "IFNULL( t03.amend_num, 0 ) AS amend_num,",
            "t03.add_date, ",
            "t05.in_school_time, ",
            "t03.pass_date_time  pass_date_time1 ",
            "FROM",
            "(",
            "SELECT ",
            "td.*, ",
            "td.sourse_id AS teacher_id,",
            "tm.team_name,",
            "tm.id AS team_id,",
            "tm.pid AS team_pid ",
            "FROM",
            "xmy_erp_db.track_market AS tm",
            "LEFT JOIN xmy_erp_db.track_detail AS td ON tm.id = td.track_id AND tm.deleted = td.deleted ",
            "WHERE ",
            "tm.classify = ${classify} ",
            "AND tm.track_type = ${trackType} ",
            "AND tm.`status` = 1 ",
            "AND tm.deleted = 0 ",
            "AND tm.year_part = ${yearPart} ",
            "AND tm.quarter_num = ${quarterNum} ",
            "AND tm.id in(${teamId})",
            "AND td.sourse_id = ${teacherId}",
            "GROUP BY tm.id,td.sourse_id ",
            ") AS t1",
            "INNER JOIN (",

            "<when test= 'moldType == 1'>",
                "SELECT",
                "t1.*,",
                "t1.class_type_id_new AS class_type_id,",
                "t2.teacher_id,",
                "t5.linkman_phone",
                "FROM",
                "xmy_erp_db.student_grade AS t1",
                "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id ",
                "INNER JOIN per_student_account AS t3 ON t1.student_id = t3.student_id",
                "INNER JOIN xmy_erp_db.student AS t5 ON t1.student_id = t5.id",
                "LEFT JOIN xmy_erp_db.rade_exclude_student AS t4 ON t4.classify_id = 0 AND t4.deleted = 0 AND t4.type = 2 AND t1.student_id = t4.student_id AND t1.year_part = t4.year_part AND t1.quarter_num = t4.quarter_num AND ( FIND_IN_SET( t1.subjects_id, t4.subjects_ids ) OR t4.subjects_ids IS NULL ) AND ( FIND_IN_SET( t1.school_id, t4.school_ids ) OR t4.school_ids IS NULL ) ",
                "WHERE",
                "t1.year_part = ${yearPart} ",
                "AND t1.quarter_num = ${quarterNum}",
                "AND t1.lesson_type = 1",
                "AND t1.deleted = 0 ",
                "AND t1.subjects_id = ${subjectsId} ",
                "AND t1.is_last = 1 ",
                "<when test='include!=null and include!=&apos;&apos;'>",
                    "<when test='include == 0'>",
                        "and t4.id is null ",
                    "</when>",
                    "<when test='include == 1'>",
                        "and t4.id is not null ",
                    "</when>",
                "</when>",
                "<when test='isBeforQuarter == 0 and readingType == 1'>",
                    "AND t1.reading_status IN (1,5) ",
                "</when>",
                "<when test='isBeforQuarter == 1 and readingType == 1'>",
                    "AND t1.reading_status IN (1,5)",
                "</when>",
                "<when test='readingType == 2'>",
                    "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and use_course_count > 0)) ",
                "</when>",
                "AND t1.STATUS &lt;&gt; 3 ",
                "AND t1.deleted = 0 ",
                "<when test='gradeId!=null and gradeId!=&apos;&apos;'>",
                    "and t1.grade_id = ${gradeId}",
                "</when>",
                "<when test='studentName!=null and studentName!=&apos;&apos;'>",
                    "AND t1.student_id IN (SELECT id FROM xmy_erp_db.student WHERE `name` LIKE '%${studentName}%' AND `status` = 1 AND deleted = 0)",
                "</when>",
//                "<when test='schoolIdStr!=null and schoolIdStr!=&apos;&apos;'>",
//                    "and t1.school_id in(${schoolIdStr})",
//                "</when>",
//                "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
//                    "and t2.year_class_id in(${yearClassIdStr})",
//                "</when>",
//                "<when test='yearClassIdStr==null or yearClassIdStr==&apos;&apos; '>",
//                    "and t2.year_class_id &lt; 13",
//                "</when>",
            "and(",
            "(",
            "t1.school_id IN (${schoolIdStr})",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos;'>",
            "AND t2.year_class_id IN (${yearClassIdStr})",
            "</when>",
            ")",
            "or",
            "(",
            "t1.school_id IN (${leadSchoolIds})",
            "and t2.year_class_id IN (${leadYearClassIds})",
            "and t2.teacher_id IN (${leadTeacherId})",
            ")",
            ")",

                "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
                    "and t1.class_type_id_new IN (${classTypeId})",
                "</when>",
                "and t2.teacher_id = ${teacherId}",
                "GROUP BY",
                "student_id ",
            "</when>",

            "<when test= 'moldType == 2'>",
                "SELECT",
                "t02.*, ",
                "t02.class_type_id_new AS class_type_id,",
                "t03.teacher_id,",
                "t03.`name` AS grade_name,",
                "staff.`name` AS teacher_name, ",
                "t06.linkman_phone ",
                "FROM",
                "(",
                "SELECT",
                "t1.school_id,",
                "t1.old_teacher_id AS teacher_id,",
                "t1.student_id,",
                "t1.`status`,",
                "t1.reach_type,",
                "t1.old_grade_id AS grade_id,",
                "t1.subjects_id,",
                "t1.year_class_id,",
                "t1.time_start,",
                "t1.time_end,",
                "t1.course_type, ",
                "t1.lesson_num,",
                "t1.school_date,",
                "t10.year_part,",
                "t10.quarter_num ",
                "FROM",
                "xmy_erp_db.record_course AS t1 ",
                "INNER JOIN xmy_erp_db.grade AS t10 ON t1.grade_id = t10.id AND t10.is_rebrush = 0 ",
                "WHERE",
                "t1.deleted = 0 ",
                "AND t1.year_part = ${yearPart} ",
                "AND t1.`quarter` = ${quarterNum} ",
                "AND t1.`lesson_type` = 3 ",
                "AND t1.old_teacher_id IS NOT NULL ",
                "AND ((t1.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ) OR ( t1.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' AND t1.course_type = 7 )) ",

                "UNION ALL",

                "SELECT",
                "t4.school_id,",
                "t4.teacher_id,",
                "t1.student_id,",
                "t5.`status`,",
                "t5.reach_type,",
                "t6.grade_id,",
                "t2.subjects_id,",
                "t4.year_class_id,",
                "t2.time_start,",
                "t2.time_end,",
                "1 AS course_type, ",
                "t2.lesson_num,",
                "t2.school_date, ",
                "t10.year_part,",
                "t10.quarter_num ",
                "FROM",
                "xmy_erp_db.${courseSchedulingDetailName} AS t2",
                "INNER JOIN xmy_erp_db.grade AS t10 ON t2.grade_id = t10.id AND t10.is_rebrush = 0 ",
                "INNER JOIN xmy_erp_db.student_grade AS t1 ON t2.year_part = t1.year_part ",
                "AND t2.`quarter` = t1.quarter_num ",
                "AND t2.deleted = t1.deleted ",
                "AND t2.grade_id = t1.grade_id ",
                "AND t2.lesson_type = t1.lesson_type ",
                "<when test='isBeforQuarter == 0 and readingType == 1'>",
                    "AND t1.reading_status IN (1,5) ",
                "</when>",
                "<when test='isBeforQuarter == 1 and readingType == 1'>",
                    "AND t1.reading_status IN (1,5)",
                "</when>",
                "<when test='readingType == 2'>",
                    "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and t1.use_course_count > 0)) ",
                "</when>",
                "AND t1.`status` = 1",
                "INNER JOIN xmy_erp_db.student_grade AS t6 ON t6.year_part = t1.year_part ",
                "AND t6.`quarter_num` = t1.quarter_num ",
                "AND t6.deleted = t1.deleted ",
                "AND t6.subjects_id = t1.subjects_id ",
                "AND t6.`student_id` = t1.student_id ",
                "AND t6.lesson_type = 1 ",
                "<when test='isBeforQuarter == 0 and readingType == 1'>",
                    "AND t6.reading_status IN (1,5) ",
                "</when>",
                "<when test='isBeforQuarter == 1 and readingType == 1'>",
                    "AND t6.reading_status IN (1,5)",
                "</when>",
                "<when test='readingType == 2'>",
                    "AND ((t6.reading_status IN (1,5)) or (t6.reading_status in(3,4) and t6.use_course_count > 0)) ",
                "</when>",
                "AND t6.`status` = 1",
                "AND t2.end_date_time &gt;= t6.created_at",
                "LEFT JOIN xmy_erp_db.repair_course AS t3 ON t3.out_scheduling_detail_id = t2.id AND t3.deleted = 0",
                "AND t3.student_id = t1.student_id",
                "LEFT JOIN xmy_erp_db.grade AS t4 ON t6.grade_id = t4.id",
                "LEFT JOIN xmy_erp_db.record_course AS t5 ON t5.scheduling_detail_id = t2.id ",
                "AND t5.student_id = t1.student_id ",
                "AND t5.deleted = 0 ",
                "WHERE",
                "t2.year_part = ${yearPart} ",
                "AND t2.`quarter` = ${quarterNum} ",
                "AND t2.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
                "AND t2.lesson_type = 3 ",
                "AND t2.deleted = 0 ",
                "AND t2.`status` &lt;&gt; 2 ",
                "AND t3.id IS NULL ",
                "GROUP BY",
                "t2.id,",
                "t1.school_id,",
                "t1.subjects_id,",
                "t1.student_id,",
                "t1.lesson_type ",
                ") AS t01",
                "INNER JOIN xmy_erp_db.student_grade AS t02 ON t01.student_id = t02.student_id ",
                "AND t01.subjects_id = t02.subjects_id ",
                "AND t01.year_part = t02.year_part ",
                "AND t01.quarter_num = t02.quarter_num ",
                "AND t02.lesson_type = 1 ",
                "AND t02.deleted = 0 ",
                "AND t02.is_last = 1 ",
                "INNER JOIN xmy_erp_db.grade AS t03 ON t02.grade_id = t03.id ",
                "INNER JOIN xmy_erp_db.staff ON staff.id = t03.teacher_id ",
                "LEFT JOIN xmy_erp_db.rade_exclude_student AS t04 ON t04.classify_id = 0 ",
                "AND t04.deleted = 0 ",
                "AND t04.type = 2 ",
                "AND t02.student_id = t04.student_id ",
                "AND t02.year_part = t04.year_part ",
                "AND t02.quarter_num = t04.quarter_num ",
                "AND ( FIND_IN_SET( t02.subjects_id, t04.subjects_ids ) OR t04.subjects_ids IS NULL ) ",
                "AND ( FIND_IN_SET( t02.school_id, t04.school_ids ) OR t04.school_ids IS NULL ) ",
                "INNER JOIN per_student_account AS t05 ON t05.student_id = t01.student_id ",
                "INNER JOIN xmy_erp_db.student AS t06 ON t01.student_id = t06.id ",
                "LEFT JOIN xmy_erp_db.cha_study_plan AS csp ON t01.student_id = csp.student_id ",
                "AND csp.subjects_id = t01.subjects_id ",
                "AND csp.lesson_type = 3 ",
                "AND csp.`status` = 1 ",
                "AND csp.year_part = ${yearPart}",
                "AND csp.quarter_num = ${quarterNum} ",
                "AND school_date BETWEEN csp.start_task_date AND csp.end_task_date ",
                "AND DATE(csp.created_at) &lt; school_date ",
                "WHERE ",
//                "((t01.`status` = 1 AND course_type &lt;&gt; 7 ) OR ( course_type = 7 )) ",
                "t01.`status` = 1 ",
                "AND t02.`status` &lt;&gt; 3 ",
                "AND t03.year_part = ${yearPart} ",
                "AND t03.quarter_num = ${quarterNum} ",
                "AND t03.lesson_type = 1 ",
                "AND csp.student_id IS NULL",
                "AND t03.subjects_id IN (${subjectsId}) ",
//                "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
//                    "AND t03.year_class_id in(${yearClassIdStr}) ",
//                "</when>",
//                "<when test='yearClassIdStr==null or yearClassIdStr==&apos;&apos; '>",
//                    "AND t03.year_class_id &lt; 13 ",
//                "</when>",
                "<when test='include!=null and include!=&apos;&apos;'>",
                    "<when test='include == 0'>",
                        "AND t04.id IS NULL  ",
                    "</when>",
                    "<when test='include == 1'>",
                        "AND t04.id IS NOT NULL  ",
                    "</when>",
                "</when>",
                "<when test='isBeforQuarter == 0 and readingType == 1'>",
                    "AND t02.reading_status IN (1,5) ",
                "</when>",
                "<when test='isBeforQuarter == 1 and readingType == 1'>",
                    "AND t02.reading_status IN (1,5)",
                "</when>",
                "<when test='readingType == 2'>",
                    "AND ((t02.reading_status IN (1,5)) or (t02.reading_status in(3,4) and t02.use_course_count > 0)) ",
                "</when>",
//                "<when test='schoolIdStr!=null and schoolIdStr!=&apos;&apos; and (type == 2 || type == 4)'>",
//                    "AND t03.school_id in(${schoolIdStr}) ",
//                "</when>",
//                "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
//                    "AND t03.teacher_id in(${teacherId}) ",
//                "</when>",

                "and(",
                "(",
                "t03.school_id IN (${schoolIdStr})",
                "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos;'>",
                "AND t03.year_class_id IN (${yearClassIdStr})",
                "</when>",
                ")",
                "or",
                "(",
                "t03.school_id IN (${leadSchoolIds})",
                "and t03.year_class_id IN (${leadYearClassIds})",
                "and t03.teacher_id IN (${leadTeacherId})",
                ")",
                ")",

                "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
                    "AND t02.class_type_id_new IN (${classTypeId}) ",
                "</when>",
                "GROUP BY student_id",
            "</when>",

            ") AS t01 ON t01.teacher_id = t1.teacher_id ",
            "AND ( find_in_set( t01.year_class_id, t1.year_class_id_str ) OR t1.year_class_id_str = '' ) ",
            "AND ( find_in_set( t01.school_id, t1.school_id_str ) OR t1.school_id_str = '' ) ",
            "INNER JOIN ( SELECT * FROM edu_task WHERE deleted = 0 and task_category_id =${taskCategoryId} and subjects_id = ${subjectsId} and task_course_num BETWEEN ${lessonNumStart} and ${lessonNum}) AS t02 ON t01.year_part = t02.year_part ",
            "AND t01.quarter_num = t02.quarter_num ",
            "AND t01.subjects_id = t02.subjects_id ",
            "AND t01.class_type_id = t02.class_type_id",
            "AND t01.year_class_id = t02.year_class_id",
            "<when test='(inType != 2)'>",
            "LEFT ",
            "</when>",
            "<when test='(inType == 2)'>",
            "INNER",
            "</when>",
            "JOIN (SELECT",
            "student_id,",
            "add_date,",
            "lesson_num_finish,",
            "year_class_id,",
            "course_version_id,",
            "class_type_id,",
            "year_part,",
            "quarter_num,",
            "IFNULL( lesson_num, 0 ) AS lesson_num,",
            "right_num,",
            "is_last,",
            "is_first,",
            "amend_num, ",
            "lowest_shutnum, ",
            "brush_count, ",
            "pass_rade,",
            "pass_date_time ",
            "FROM",
            "cha_plan ",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND quarter_num = ${quarterNum}",
            "AND task_category_id = ${taskCategoryId}",
            "and deleted = 0",
            "<when test='rightNumStartDate != &apos;&apos; and rightNumEndDate != &apos;&apos;'>",
            "AND add_date BETWEEN '${rightNumStartDate}' AND '${rightNumEndDate}' ",
            "AND right_num &gt; 0 ",
            "</when>",
            ") AS t03 ON t01.year_part = t03.year_part ",
            "AND t01.quarter_num = t03.quarter_num ",
            "AND t01.student_id = t03.student_id ",
            "AND t02.year_class_id = t03.year_class_id ",
            "AND t02.class_type_id = t03.class_type_id ",
            "AND t02.course_version_id = t03.course_version_id",
            "<when test='courseVersionId!=null and courseVersionId!=&apos;&apos;'>",
            "and t02.course_version_id = ${courseVersionId}",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and t01.subjects_id = ${subjectsId}",
            "</when>",
            "AND t02.task_course_num = t03.lesson_num",
            "<when test='radeType!=null and radeType == 1 '>",
                "<when test='passType!=null and passType!=&apos;&apos; and passType != 9 and passType != 10 and passType != 11 and passType != 12'>",
                    "and t03.is_last = 1",
                "</when>",
                "<when test='passType!=null and passType!=&apos;&apos; and (passType == 9 or passType == 10 or passType == 11 or passType == 12 )'>",
                    "and t03.is_first = 1",
                "</when>",
            "</when>",
            "<when test='radeType!=null and (radeType == 2 or radeType == 3) '>",
            "and t03.is_first = 1",
            "</when>",

            "LEFT JOIN ( ",
            "SELECT",
            "id,",
            "student_id,",
            "add_date,",
            "lesson_num_finish,",
            "year_class_id,",
            "course_version_id,",
            "class_type_id,",
            "year_part,",
            "quarter_num,",
            "IFNULL( lesson_num, 0 ) AS lesson_num,",
            "right_num,",
            "is_last,",
            "is_first,",
            "amend_num,",
            "pass_rade,",
            "brush_count,",
            "lowest_shutnum",
            "FROM",
            "cha_plan",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND quarter_num = ${quarterNum} ",
            "AND task_category_id = ${taskCategoryId} ",
            "AND deleted = 0",
            ") AS t04 ON t04.year_part = t03.year_part ",
            "AND t04.quarter_num = t03.quarter_num ",
            "AND t04.student_id = t03.student_id ",
            "AND t04.year_class_id = t03.year_class_id ",
            "AND t04.course_version_id = t03.course_version_id ",
            "AND t04.class_type_id = t03.class_type_id ",
            "AND t04.lesson_num = t03.lesson_num ",
            "and t04.is_last = 1 ",
            "and t04.is_first = 0 ",
            // 计算在校时长：
            // 正常情况：签退时间-签到时间 = 在校时间
            // 签到时间为空：如果当前时间和add_date是同一天，并且当前时间没有超过23点，那么使用当前时间减去签到时间，计算在校时间
            // 签到时间为空：如果当前时间和add_date是同一天，并且当前时间超过23点，那么显示“无效”
            // 签到时间为空：如果当前时间和add_date不是同一天，那么显示“无效”
            // 多选日期，在校时长相加，并且不计算无效时间数据
            "LEFT JOIN ( ",
            "SELECT",
            "student_id,subjects_id,IF(SUM(in_school_time) = 0, '无效', IFNULL(SUM(in_school_time), 0)) AS in_school_time ",
            "FROM ",
            "( ",
            "SELECT t1.student_id,t1.subjects_id,t1.school_date,",
            "CASE ",
            "WHEN in_date_time IS NOT NULL AND out_date_time IS NOT NULL THEN TIMESTAMPDIFF( MINUTE, in_date_time, out_date_time ) ",
            "WHEN in_date_time IS NOT NULL AND out_date_time IS NULL THEN ",
            "CASE ",
            "WHEN DATE ( add_date ) = CURDATE() AND HOUR (NOW()) &lt; 23 THEN TIMESTAMPDIFF( MINUTE, in_date_time, NOW()) ",
            "WHEN DATE ( add_date ) = CURDATE() AND HOUR ( NOW()) &gt;= 23 THEN 0 ELSE 0 END ELSE 0 END AS in_school_time ",
            "FROM",
            "xmy_erp_db.record_course AS t1 ",
            "LEFT JOIN xmy_erp_db.student_sign_in AS t2 ON t1.scheduling_detail_id = t2.scheduling_detail_id AND t1.student_id = t2.student_id AND t2.add_date = t1.school_date AND t2.subjects_id = t1.subjects_id",
            "WHERE ",
            "t1.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
            "AND t1.lesson_type = 3",
            "AND t1.subjects_id = ${subjectsId}",
            ") AS student_sign_in ",
            "GROUP BY ",
            "student_id ",
            ") t05 ON t05.student_id = t01.student_id AND t05.subjects_id = t01.subjects_id ",
            "LEFT JOIN tb_school_time_01 AS t07 ON t01.year_part = t07.year_part AND t01.quarter_num = t07.quarter_num AND t01.student_id = t07.student_id ",

//            "GROUP BY t01.student_id",
            ") AS t",
            "where 1=1",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 2'>",// 已通关
                  " AND ((( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR ( brush_count_temp &gt;= 2 AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR ( not_brush = 1 AND ( right_num + amend_num ) &gt;= lowest_shutnum )) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
//                " AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND ( right_num + amend_num &gt;= lowest_shutnum ) AND lowest_shutnum &lt;&gt; 0 ",
//                " AND ( right_num + amend_num ) &gt;= lowest_shutnum AND lowest_shutnum &lt;&gt; 0",
//                " AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND lowest_shutnum &lt;&gt; 0",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 3'>",// 未通关
                " AND ((not_brush = 0 and brush_count_temp &lt;= 1 AND (right_num / lowest_shutnum )* 100 &lt; pass_rade ) OR (not_brush = 0 and brush_count_temp &gt;= 2 AND ( right_num + amend_num ) &lt; lowest_shutnum ) OR (( right_num / lowest_shutnum )* 100 &gt;= pass_rade  AND ( right_num + amend_num ) &lt; lowest_shutnum ) OR ( not_brush = 1 AND ( right_num + amend_num ) &lt; lowest_shutnum )) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
//                " AND ((( right_num / lowest_shutnum )* 100 &lt; pass_rade) OR ((right_num / lowest_shutnum * 100 &gt;= pass_rade) AND (right_num + amend_num &lt; lowest_shutnum))) AND lowest_shutnum &lt;&gt; 0 ",
//                " AND (  ( right_num + amend_num ) &lt; lowest_shutnum and lowest_shutnum &lt;&gt; 0)",
//                " AND (  ( right_num / lowest_shutnum )* 100 &lt; pass_rade and lowest_shutnum &lt;&gt; 0)",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 4'>",// 今日已通关
                " AND ((( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR ( brush_count_temp &gt;= 2 AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR (not_brush = 1 and ( right_num + amend_num ) &gt;= lowest_shutnum)) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
//                " AND ( right_num + amend_num ) &gt;= lowest_shutnum AND lowest_shutnum &lt;&gt; 0",
//                " AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND lowest_shutnum &lt;&gt; 0 ",
            "and add_date BETWEEN '${passDateStart}' AND '${passDateEnd}'",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 5'>",// 未刷（未完成）
            "and brush_count_temp = 0 AND (right_num =0 and amend_num=0  and lowest_shutnum is not null)",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 6'>", // 通关率——>需复刷
//                  "AND brush_count_temp &gt;= 1 AND brush_count_temp &lt;= 2 AND (right_num + amend_num) &lt; lowest_shutnum AND lowest_shutnum &lt;&gt; 0",
                "AND brush_count_temp &gt;= 1 AND (brush_count_temp &lt; 2 OR (right_num + amend_num &lt; lowest_shutnum)) AND ((( right_num / lowest_shutnum )* 100 &lt; pass_rade) OR ((right_num / lowest_shutnum * 100 &gt;= pass_rade) AND (right_num + amend_num &lt; lowest_shutnum))) AND lowest_shutnum &lt;&gt; 0",
//                "and brush_count_temp &gt;= 1 AND ((( right_num / lowest_shutnum )* 100 &lt; pass_rade ) and lowest_shutnum &lt;&gt; 0)",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 7'>",// 已完成详情
                "AND brush_count_temp &gt; 0 AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 8'>",// 根据日期已完成详情
                "AND brush_count_temp &gt; 0 AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL",
                "and add_date BETWEEN '${passDateStart}' AND '${passDateEnd}'",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 9'>",// 应复刷详情
                "AND is_first = 1  ",
                "AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade )",
                "AND lowest_shutnum &lt;&gt; 0 ",
                "AND lowest_shutnum IS NOT NULL ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 10'>",// 已复刷详情
                "AND is_first = 1 ",
                "AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade ) ",
                "AND lowest_shutnum &lt;&gt; 0 ",
                "AND lowest_shutnum IS NOT NULL ",
                "AND again_brush_id IS NOT NULL ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 11'>",// 根据日期已复刷详情
                "AND is_first = 1 ",
                "AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade ) ",
                "AND lowest_shutnum &lt;&gt; 0 ",
                "AND lowest_shutnum IS NOT NULL ",
                "AND again_brush_id IS NOT NULL ",
                "and add_date BETWEEN '${passDateStart}' AND '${passDateEnd}'",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 12'>",// 未复刷
                "AND is_first = 1  ",
                "AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade )",
                "AND lowest_shutnum &lt;&gt; 0 ",
                "AND lowest_shutnum IS NOT NULL ",
                "AND again_brush_id IS NULL ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 13'>",// 应修正
                "AND brush_count_temp &gt;= 1 AND ( right_num + amend_num ) &lt; lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 14'>",// 已完成（正确+修正>=应通关）
                "AND brush_count_temp = 1 AND (right_num + amend_num) &gt;= lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 15'>",// 今日已完成（正确+修正>=应通关）
                "AND brush_count_temp = 1 AND (right_num + amend_num) &gt;= lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
                "AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 16'>",// 需修正（第一次需修正）
                "AND brush_count_temp = 1 AND ( right_num + amend_num ) &lt; lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 17'>",// 复刷应通关
                "AND (brush_count_temp &gt;= 1 AND (brush_count_temp &lt; 2 OR ( right_num + amend_num &lt; lowest_shutnum )) AND (((right_num / lowest_shutnum )* 100 &lt; pass_rade ) OR (( right_num / lowest_shutnum * 100 &gt;= pass_rade ) AND ( right_num + amend_num &lt; lowest_shutnum ))) OR brush_count_temp &gt;= 2 ) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 18'>",// 复刷已通关
                "AND (( brush_count_temp &gt;= 2 AND (( right_num + amend_num ) &gt;= lowest_shutnum AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade ))) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 19'>",// 复刷未通关
                "AND ( brush_count_temp &gt;= 1 AND (( right_num + amend_num ) &lt; lowest_shutnum OR ( right_num / lowest_shutnum )* 100 &lt; pass_rade )) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 20'>",// 复刷今日已通关
                "AND (( brush_count_temp &gt;= 2 AND (( right_num + amend_num ) &gt;= lowest_shutnum AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade ))) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL",
                "AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
            "</when>",
            "<when test='studentIdStr!=null and studentIdStr!=&apos;&apos; '>",
                "AND student_id IN (${studentIdStr}) ",
            "</when>",
            "<when test='listState == 1 or listState == 2'>",
                "GROUP BY student_id",
            "</when>",
            "ORDER BY pass_date_time IS NULL ASC,pass_date_time ASC,student_id,lesson_num ASC",
            "</script>"})
    public IPage<ChaPlan> getPassRadeTeamDetail(IPage<?> page,
                                                @Param("yearPart") String yearPart,
                                                @Param("quarterNum") String quarterNum,
                                                @Param("schoolIdStr") String schoolIdStr,
                                                @Param("teacherId") String teacherId,
                                                @Param("yearClassIdStr") String yearClassIdStr,
                                                @Param("type") String type,
                                                @Param("gradeId") String gradeId,
                                                @Param("lessonNumStart") String lessonNumStart,
                                                @Param("lessonNum") String lessonNum,
                                                @Param("classTypeId") String classTypeId,
                                                @Param("readingType") String readingType,
                                                @Param("passType") String passType,
                                                @Param("lessonNow") String lessonNow,
                                                @Param("isAll") String isAll,
                                                @Param("courseVersionId") Long courseVersionId,
                                                @Param("passDate") String passDate,
                                                @Param("passDateStart") String passDateStart,
                                                @Param("passDateEnd") String passDateEnd,
                                                @Param("subjectsId") Long subjectsId,
                                                @Param("isBeforQuarter") String isBeforQuarter,
                                                @Param("readingStatusStr") String readingStatusStr,
                                                @Param("rightNumStartDate") String rightNumStartDate,
                                                @Param("rightNumEndDate") String rightNumEndDate,
                                                @Param("studentName") String studentName,
                                                @Param("radeType") String radeType,
                                                @Param("listState") String listState,
                                                @Param("classify") String classify,
                                                @Param("trackType") String trackType,
                                                @Param("teamId") String teamId,
                                                @Param("include") String include,
                                                @Param("inType") String inType,
                                                @Param("taskCategoryId") Integer taskCategoryId,
                                                @Param("courseSchedulingDetailName") String courseSchedulingDetailName,
                                                @Param("studentIdStr") String studentIdStr,
                                                @Param("moldType") String moldType, // 1正常通关率、2到勤通关率
                                                @Param("leadSchoolIds") String leadSchoolIds,
                                                @Param("leadSubjectsIds") String leadSubjectsIds,
                                                @Param("leadYearClassIds") String leadYearClassIds,
                                                @Param("leadTeacherId") Long leadTeacherId
    );

    /**
     *已过刷题排班和未到刷题排班详情
     */
    @Select({"<script>",
            "WITH tb_school_time_01 AS (",
            "SELECT *,",
            "MAX( CASE WHEN subjects_id = 1 THEN school_time END ) AS en_school_time,",
            "MAX( CASE WHEN subjects_id = 2 THEN school_time END ) AS ma_school_time,",
            "MAX( CASE WHEN subjects_id = 3 THEN school_time END ) AS ph_school_time ",
            "FROM (",
            "SELECT *, ",
            "GROUP_CONCAT( time_start_end ORDER BY t.week_dates ) AS school_time ",
            "FROM (",
            "SELECT t1.id,t1.year_part,t1.quarter_num,t1.student_id,t1.subjects_id,t2.week_dates,",
            "CONCAT( getWeekdayName ( t2.week_dates ), '', t2.time_start, ' - ', t2.time_end ) AS time_start_end ",
            "FROM ",
            "xmy_erp_db.student_grade AS t1 ",
            "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id ",
            "WHERE ",
            "t1.year_part = ${yearPart} ",
            "AND t1.quarter_num = ${quarterNum} ",
            "AND t1.lesson_type &lt;&gt; 1",
            "AND t1.deleted = 0 ",
            "AND t1.`status` = 1 ",
            "<if test= 'readingType == 1'>",
            "<if test= 'isBeforQuarter == 0'>",
            "AND t1.reading_status = 1 ",
            "</if>",
            "<if test= 'isBeforQuarter == 1'>",
            "AND t1.reading_status IN (1,3,4,5,6 ) ",
            "</if>",
            "</if>",
            "<if test= 'readingType == 2'>",
            "AND t1.reading_status IN (1,3,4,5,6 ) ",
            "</if>",
            "GROUP BY t1.grade_id,t1.student_id,t1.subjects_id ",
            ") AS t ",
            "GROUP BY student_id,subjects_id ",
            ") AS t ",
            "GROUP BY student_id",
            ")",
            "<when test= 'examSchedulingtType == 1'>",
            ", wi_tb01 AS (",
            "SELECT",
            "rc.student_id",
            "FROM",
            "xmy_erp_db.record_course AS rc",
            "  INNER JOIN xmy_erp_db.student s ON s.id = rc.student_id",
            "where",
            "rc.subjects_id = ${subjectsId}",
            " and rc.year_part = ${yearPart}",
            "AND rc.quarter = ${quarterNum}",
            " AND rc.lesson_type = 3 ",
            "AND rc.deleted = 0",
            "and rc.course_type &lt;&gt; 7",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and s.year_class_id in(${yearClassIdStr})",
            "</when>",
            " AND rc.school_date BETWEEN #{schoolDateStart} AND #{schoolDateEnd}",
            "   ) ",
            "</when>",
            "<when test= 'examSchedulingtType == 2'>",
            " , wi_tb01 AS (",
            "  SELECT",
            "t1.student_id",
            "FROM",
            "xmy_erp_db.student_grade AS t1",
            "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id",
            "INNER JOIN xmy_erp_db.course_scheduling_detail AS t3 ON t1.grade_id = t3.grade_id and t3.deleted = 0",
            "INNER JOIN student s ON s.id = t1.student_id",
            "WHERE",
            "t1.year_part = ${yearPart}",
            "AND t1.quarter_num = ${quarterNum}",
            "and t1.deleted = 0",
            "AND t2.lesson_type = 3",
            "AND t1.reading_status = 1",
            "AND t1.subjects_id = 2",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and s.year_class_id in(${yearClassIdStr})",
            "</when>",
            "AND t3.school_date BETWEEN #{schoolDateStart} AND #{schoolDateEnd}",
//                "AND '2025-04-20'",
            "GROUP BY",
            "t1.student_id",
            ")",
            "</when>",

            "SELECT",
            "*,if(brush_count_temp = 0,1,brush_count_temp) as brush_count ",
            "<when test='listState != 1 and listState != 2'>",
            ",pass_date_time1 AS pass_date_time ",
            "</when>",
            "<when test='listState == 1 or listState == 2'>",
            ",MAX( pass_date_time1 ) AS pass_date_time ",
            "</when>",
            "<when test='listState == 2'>",// 正确率学员详情，为了不影响其他的合并课次数据，所以改成了2，为1的不适用于正确率
            ",GROUP_CONCAT( lesson_num ) AS LessonNumNot,",
            "SUM(lowest_shutnum) AS lowestShutnumAll,",
            "SUM(right_num) AS rightNumAll,",
            "SUM(amend_num) AS amendNumAll",
            "</when>",
            "FROM",
            "(",
            "SELECT",
            "t01.id,",
            "t01.subjects_id,",
            "t01.school_id,",
            "t01.year_part,",
            "t01.quarter_num,",
            "t02.course_version_id,",
            "t01.grade_id,",
            "t01.teacher_id,",
            "t01.class_type_id,",
            "t01.year_class_id,",
            "t01.linkman_phone,",
            "t01.student_id,",
            "t03.is_first,",
            "t03.is_last,",
            "t07.en_school_time,",
            "t07.ma_school_time,",
            "t07.ph_school_time,",
            "t04.id AS again_brush_id, ",
            "t02.task_course_num AS lesson_num,",
            "t02.not_brush,",
            "IFNULL(t03.brush_count,0) as brush_count_temp,",
            "IFNULL( t03.brush_count &gt; 0 AND t03.lowest_shutnum &lt;&gt; 0 AND t03.lowest_shutnum IS NOT NULL, 1) AS yet_finish_count, ",// 已完成
            "IFNULL( t03.is_first = 1 AND (( t03.right_num / t03.lowest_shutnum )* 100 &lt; t03.pass_rade ) AND t03.lowest_shutnum &lt;&gt; 0 AND t03.lowest_shutnum IS NOT NULL AND t03.t04.id IS NOT NULL , 1 ) AS yet_rebrush_count,",// 已复刷
            "IFNULL( t03.pass_rade,t02.pass_rade) as pass_rade, ",
            "(CASE WHEN t03.right_num IS NOT NULL AND t03.pass_rade &gt; 0 and (t03.right_num + t03.amend_num ) &gt;= t03.lowest_shutnum AND ( t03.right_num / t03.lowest_shutnum )* 100 &gt;= t03.pass_rade THEN t03.lowest_shutnum ELSE t02.lowest_shutnum END ) AS lowest_shutnum,",
            "IFNULL( t03.right_num, 0 ) AS right_num,",
            "IFNULL( t03.amend_num, 0 ) AS amend_num,",
            "t03.add_date, ",
            "t05.in_school_time, ",
            "t03.pass_date_time  pass_date_time1 ",
            "FROM",
            "(",
            "SELECT ",
            "td.*, ",
            "td.sourse_id AS teacher_id,",
            "tm.team_name,",
            "tm.id AS team_id,",
            "tm.pid AS team_pid ",
            "FROM",
            "xmy_erp_db.track_market AS tm",
            "LEFT JOIN xmy_erp_db.track_detail AS td ON tm.id = td.track_id AND tm.deleted = td.deleted ",
            "WHERE ",
            "tm.classify = ${classify} ",
            "AND tm.track_type = ${trackType} ",
            "AND tm.`status` = 1 ",
            "AND tm.deleted = 0 ",
            "AND tm.year_part = ${yearPart} ",
            "AND tm.quarter_num = ${quarterNum} ",
            "AND tm.id in(${teamId})",
            "AND td.sourse_id = ${teacherId}",
            "GROUP BY tm.id,td.sourse_id ",
            ") AS t1",
            "INNER JOIN (",

            "<when test= 'moldType == 1'>",
            "SELECT",
            "t1.*,",
            "t1.class_type_id_new AS class_type_id,",
            "t2.teacher_id,",
            "t5.linkman_phone",
            "FROM",
            "xmy_erp_db.student_grade AS t1",
            "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id ",
            "INNER JOIN per_student_account AS t3 ON t1.student_id = t3.student_id",
            // 已过刷题排班和未到刷题排班
            "INNER JOIN wi_tb01 on t1.student_id = wi_tb01.student_id",

            "INNER JOIN xmy_erp_db.student AS t5 ON t1.student_id = t5.id",
            "LEFT JOIN xmy_erp_db.rade_exclude_student AS t4 ON t4.classify_id = 0 AND t4.deleted = 0 AND t4.type = 2 AND t1.student_id = t4.student_id AND t1.year_part = t4.year_part AND t1.quarter_num = t4.quarter_num AND ( FIND_IN_SET( t1.subjects_id, t4.subjects_ids ) OR t4.subjects_ids IS NULL ) AND ( FIND_IN_SET( t1.school_id, t4.school_ids ) OR t4.school_ids IS NULL ) ",
            "WHERE",
            "t1.year_part = ${yearPart} ",
            "AND t1.quarter_num = ${quarterNum}",
            "AND t1.lesson_type = 1",
            "AND t1.deleted = 0 ",
            "AND t1.subjects_id = ${subjectsId} ",
            "AND t1.is_last = 1 ",
            "<when test='include!=null and include!=&apos;&apos;'>",
            "<when test='include == 0'>",
            "and t4.id is null ",
            "</when>",
            "<when test='include == 1'>",
            "and t4.id is not null ",
            "</when>",
            "</when>",
            "<when test='isBeforQuarter == 0 and readingType == 1'>",
            "AND t1.reading_status IN (1,5) ",
            "</when>",
            "<when test='isBeforQuarter == 1 and readingType == 1'>",
            "AND t1.reading_status IN (1,5)",
            "</when>",
            "<when test='readingType == 2'>",
            "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and use_course_count > 0)) ",
            "</when>",
            "AND t1.STATUS &lt;&gt; 3 ",
            "AND t1.deleted = 0 ",
            "<when test='gradeId!=null and gradeId!=&apos;&apos;'>",
            "and t1.grade_id = ${gradeId}",
            "</when>",
            "<when test='studentName!=null and studentName!=&apos;&apos;'>",
            "AND t1.student_id IN (SELECT id FROM xmy_erp_db.student WHERE `name` LIKE '%${studentName}%' AND `status` = 1 AND deleted = 0)",
            "</when>",
            "<when test='schoolIdStr!=null and schoolIdStr!=&apos;&apos;'>",
            "and t1.school_id in(${schoolIdStr})",
            "</when>",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and t2.year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='yearClassIdStr==null or yearClassIdStr==&apos;&apos; '>",
            "and t2.year_class_id &lt; 13",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and t1.class_type_id_new IN (${classTypeId})",
            "</when>",
            "and t2.teacher_id = ${teacherId}",
            "GROUP BY",
            "student_id ",
            "</when>",

            "<when test= 'moldType == 2'>",
            "SELECT",
            "t02.*, ",
            "t02.class_type_id_new AS class_type_id,",
            "t03.teacher_id,",
            "t03.`name` AS grade_name,",
            "staff.`name` AS teacher_name, ",
            "t06.linkman_phone ",
            "FROM",
            "(",
            "SELECT",
            "t1.school_id,",
            "t1.old_teacher_id AS teacher_id,",
            "t1.student_id,",
            "t1.`status`,",
            "t1.reach_type,",
            "t1.old_grade_id AS grade_id,",
            "t1.subjects_id,",
            "t1.year_class_id,",
            "t1.time_start,",
            "t1.time_end,",
            "t1.course_type, ",
            "t1.lesson_num,",
            "t1.school_date,",
            "t10.year_part,",
            "t10.quarter_num ",
            "FROM",
            "xmy_erp_db.record_course AS t1 ",
            "INNER JOIN xmy_erp_db.grade AS t10 ON t1.grade_id = t10.id AND t10.is_rebrush = 0 ",
            "WHERE",
            "t1.deleted = 0 ",
            "AND t1.year_part = ${yearPart} ",
            "AND t1.`quarter` = ${quarterNum} ",
            "AND t1.`lesson_type` = 3 ",
            "AND t1.old_teacher_id IS NOT NULL ",
            "AND ((t1.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ) OR ( t1.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' AND t1.course_type = 7 )) ",

            "UNION ALL",

            "SELECT",
            "t4.school_id,",
            "t4.teacher_id,",
            "t1.student_id,",
            "t5.`status`,",
            "t5.reach_type,",
            "t6.grade_id,",
            "t2.subjects_id,",
            "t4.year_class_id,",
            "t2.time_start,",
            "t2.time_end,",
            "1 AS course_type, ",
            "t2.lesson_num,",
            "t2.school_date, ",
            "t10.year_part,",
            "t10.quarter_num ",
            "FROM",
            "xmy_erp_db.${courseSchedulingDetailName} AS t2",
            "INNER JOIN xmy_erp_db.grade AS t10 ON t2.grade_id = t10.id AND t10.is_rebrush = 0 ",
            "INNER JOIN xmy_erp_db.student_grade AS t1 ON t2.year_part = t1.year_part ",
            "AND t2.`quarter` = t1.quarter_num ",
            "AND t2.deleted = t1.deleted ",
            "AND t2.grade_id = t1.grade_id ",
            "AND t2.lesson_type = t1.lesson_type ",
            "<when test='isBeforQuarter == 0 and readingType == 1'>",
            "AND t1.reading_status IN (1,5) ",
            "</when>",
            "<when test='isBeforQuarter == 1 and readingType == 1'>",
            "AND t1.reading_status IN (1,5)",
            "</when>",
            "<when test='readingType == 2'>",
            "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and t1.use_course_count > 0)) ",
            "</when>",
            "AND t1.`status` = 1",
            "INNER JOIN xmy_erp_db.student_grade AS t6 ON t6.year_part = t1.year_part ",
            "AND t6.`quarter_num` = t1.quarter_num ",
            "AND t6.deleted = t1.deleted ",
            "AND t6.subjects_id = t1.subjects_id ",
            "AND t6.`student_id` = t1.student_id ",
            "AND t6.lesson_type = 1 ",
            "<when test='isBeforQuarter == 0 and readingType == 1'>",
            "AND t6.reading_status IN (1,5) ",
            "</when>",
            "<when test='isBeforQuarter == 1 and readingType == 1'>",
            "AND t6.reading_status IN (1,5)",
            "</when>",
            "<when test='readingType == 2'>",
            "AND ((t6.reading_status IN (1,5)) or (t6.reading_status in(3,4) and t6.use_course_count > 0)) ",
            "</when>",
            "AND t6.`status` = 1",
            "AND t2.end_date_time &gt;= t6.created_at",
            "LEFT JOIN xmy_erp_db.repair_course AS t3 ON t3.out_scheduling_detail_id = t2.id AND t3.deleted = 0",
            "AND t3.student_id = t1.student_id",
            "LEFT JOIN xmy_erp_db.grade AS t4 ON t6.grade_id = t4.id",
            "LEFT JOIN xmy_erp_db.record_course AS t5 ON t5.scheduling_detail_id = t2.id ",
            "AND t5.student_id = t1.student_id ",
            "AND t5.deleted = 0 ",
            "WHERE",
            "t2.year_part = ${yearPart} ",
            "AND t2.`quarter` = ${quarterNum} ",
            "AND t2.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
            "AND t2.lesson_type = 3 ",
            "AND t2.deleted = 0 ",
            "AND t2.`status` &lt;&gt; 2 ",
            "AND t3.id IS NULL ",
            "GROUP BY",
            "t2.id,",
            "t1.school_id,",
            "t1.subjects_id,",
            "t1.student_id,",
            "t1.lesson_type ",
            ") AS t01",
            "INNER JOIN xmy_erp_db.student_grade AS t02 ON t01.student_id = t02.student_id ",
            "AND t01.subjects_id = t02.subjects_id ",
            "AND t01.year_part = t02.year_part ",
            "AND t01.quarter_num = t02.quarter_num ",
            "AND t02.lesson_type = 1 ",
            "AND t02.deleted = 0 ",
            "AND t02.is_last = 1 ",
            "INNER JOIN xmy_erp_db.grade AS t03 ON t02.grade_id = t03.id ",
            "INNER JOIN xmy_erp_db.staff ON staff.id = t03.teacher_id ",
            "LEFT JOIN xmy_erp_db.rade_exclude_student AS t04 ON t04.classify_id = 0 ",
            "AND t04.deleted = 0 ",
            "AND t04.type = 2 ",
            "AND t02.student_id = t04.student_id ",
            "AND t02.year_part = t04.year_part ",
            "AND t02.quarter_num = t04.quarter_num ",
            "AND ( FIND_IN_SET( t02.subjects_id, t04.subjects_ids ) OR t04.subjects_ids IS NULL ) ",
            "AND ( FIND_IN_SET( t02.school_id, t04.school_ids ) OR t04.school_ids IS NULL ) ",
            "INNER JOIN per_student_account AS t05 ON t05.student_id = t01.student_id ",
            "INNER JOIN xmy_erp_db.student AS t06 ON t01.student_id = t06.id ",
            "LEFT JOIN xmy_erp_db.cha_study_plan AS csp ON t01.student_id = csp.student_id ",
            "AND csp.subjects_id = t01.subjects_id ",
            "AND csp.lesson_type = 3 ",
            "AND csp.`status` = 1 ",
            "AND csp.year_part = ${yearPart}",
            "AND csp.quarter_num = ${quarterNum} ",
            "AND school_date BETWEEN csp.start_task_date AND csp.end_task_date ",
            "AND DATE(csp.created_at) &lt; school_date ",
            "WHERE ",
//                "((t01.`status` = 1 AND course_type &lt;&gt; 7 ) OR ( course_type = 7 )) ",
            "t01.`status` = 1 ",
            "AND t02.`status` &lt;&gt; 3 ",
            "AND t03.year_part = ${yearPart} ",
            "AND t03.quarter_num = ${quarterNum} ",
            "AND t03.lesson_type = 1 ",
            "AND csp.student_id IS NULL",
            "AND t03.subjects_id IN (${subjectsId}) ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "AND t03.year_class_id in(${yearClassIdStr}) ",
            "</when>",
            "<when test='yearClassIdStr==null or yearClassIdStr==&apos;&apos; '>",
            "AND t03.year_class_id &lt; 13 ",
            "</when>",
            "<when test='include!=null and include!=&apos;&apos;'>",
            "<when test='include == 0'>",
            "AND t04.id IS NULL  ",
            "</when>",
            "<when test='include == 1'>",
            "AND t04.id IS NOT NULL  ",
            "</when>",
            "</when>",
            "<when test='isBeforQuarter == 0 and readingType == 1'>",
            "AND t02.reading_status IN (1,5) ",
            "</when>",
            "<when test='isBeforQuarter == 1 and readingType == 1'>",
            "AND t02.reading_status IN (1,5)",
            "</when>",
            "<when test='readingType == 2'>",
            "AND ((t02.reading_status IN (1,5)) or (t02.reading_status in(3,4) and t02.use_course_count > 0)) ",
            "</when>",
            "<when test='schoolIdStr!=null and schoolIdStr!=&apos;&apos; and (type == 2 || type == 4)'>",
            "AND t03.school_id in(${schoolIdStr}) ",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
            "AND t03.teacher_id in(${teacherId}) ",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "AND t02.class_type_id_new IN (${classTypeId}) ",
            "</when>",
            "GROUP BY student_id",
            "</when>",

            ") AS t01 ON t01.teacher_id = t1.teacher_id ",
            "AND ( find_in_set( t01.year_class_id, t1.year_class_id_str ) OR t1.year_class_id_str = '' ) ",
            "AND ( find_in_set( t01.school_id, t1.school_id_str ) OR t1.school_id_str = '' ) ",
            "INNER JOIN ( SELECT * FROM edu_task WHERE deleted = 0 and task_category_id =${taskCategoryId} and subjects_id = ${subjectsId} and task_course_num BETWEEN ${lessonNumStart} and ${lessonNum}) AS t02 ON t01.year_part = t02.year_part ",
            "AND t01.quarter_num = t02.quarter_num ",
            "AND t01.subjects_id = t02.subjects_id ",
            "AND t01.class_type_id = t02.class_type_id",
            "AND t01.year_class_id = t02.year_class_id",
            "<when test='(inType != 2)'>",
            "LEFT ",
            "</when>",
            "<when test='(inType == 2)'>",
            "INNER",
            "</when>",
            "JOIN (SELECT",
            "student_id,",
            "add_date,",
            "lesson_num_finish,",
            "year_class_id,",
            "course_version_id,",
            "class_type_id,",
            "year_part,",
            "quarter_num,",
            "IFNULL( lesson_num, 0 ) AS lesson_num,",
            "right_num,",
            "is_last,",
            "is_first,",
            "amend_num, ",
            "lowest_shutnum, ",
            "brush_count, ",
            "pass_rade,",
            "pass_date_time ",
            "FROM",
            "cha_plan ",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND quarter_num = ${quarterNum}",
            "AND task_category_id = ${taskCategoryId}",
            "and deleted = 0",
            "<when test='rightNumStartDate != &apos;&apos; and rightNumEndDate != &apos;&apos;'>",
            "AND add_date BETWEEN '${rightNumStartDate}' AND '${rightNumEndDate}' ",
            "AND right_num &gt; 0 ",
            "</when>",
            ") AS t03 ON t01.year_part = t03.year_part ",
            "AND t01.quarter_num = t03.quarter_num ",
            "AND t01.student_id = t03.student_id ",
            "AND t02.year_class_id = t03.year_class_id ",
            "AND t02.class_type_id = t03.class_type_id ",
            "AND t02.course_version_id = t03.course_version_id",
            "<when test='courseVersionId!=null and courseVersionId!=&apos;&apos;'>",
            "and t02.course_version_id = ${courseVersionId}",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and t01.subjects_id = ${subjectsId}",
            "</when>",
            "AND t02.task_course_num = t03.lesson_num",
            "<when test='radeType!=null and radeType == 1 '>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType != 9 and passType != 10 and passType != 11 and passType != 12'>",
            "and t03.is_last = 1",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and (passType == 9 or passType == 10 or passType == 11 or passType == 12 )'>",
            "and t03.is_first = 1",
            "</when>",
            "</when>",
            "<when test='radeType!=null and (radeType == 2 or radeType == 3) '>",
            "and t03.is_first = 1",
            "</when>",

            "LEFT JOIN ( ",
            "SELECT",
            "id,",
            "student_id,",
            "add_date,",
            "lesson_num_finish,",
            "year_class_id,",
            "course_version_id,",
            "class_type_id,",
            "year_part,",
            "quarter_num,",
            "IFNULL( lesson_num, 0 ) AS lesson_num,",
            "right_num,",
            "is_last,",
            "is_first,",
            "amend_num,",
            "pass_rade,",
            "brush_count,",
            "lowest_shutnum",
            "FROM",
            "cha_plan",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND quarter_num = ${quarterNum} ",
            "AND task_category_id = ${taskCategoryId} ",
            "AND deleted = 0",
            ") AS t04 ON t04.year_part = t03.year_part ",
            "AND t04.quarter_num = t03.quarter_num ",
            "AND t04.student_id = t03.student_id ",
            "AND t04.year_class_id = t03.year_class_id ",
            "AND t04.course_version_id = t03.course_version_id ",
            "AND t04.class_type_id = t03.class_type_id ",
            "AND t04.lesson_num = t03.lesson_num ",
            "and t04.is_last = 1 ",
            "and t04.is_first = 0 ",
            // 计算在校时长：
            // 正常情况：签退时间-签到时间 = 在校时间
            // 签到时间为空：如果当前时间和add_date是同一天，并且当前时间没有超过23点，那么使用当前时间减去签到时间，计算在校时间
            // 签到时间为空：如果当前时间和add_date是同一天，并且当前时间超过23点，那么显示“无效”
            // 签到时间为空：如果当前时间和add_date不是同一天，那么显示“无效”
            // 多选日期，在校时长相加，并且不计算无效时间数据
            "LEFT JOIN ( ",
            "SELECT",
            "student_id,subjects_id,IF(SUM(in_school_time) = 0, '无效', IFNULL(SUM(in_school_time), 0)) AS in_school_time ",
            "FROM ",
            "( ",
            "SELECT t1.student_id,t1.subjects_id,t1.school_date,",
            "CASE ",
            "WHEN in_date_time IS NOT NULL AND out_date_time IS NOT NULL THEN TIMESTAMPDIFF( MINUTE, in_date_time, out_date_time ) ",
            "WHEN in_date_time IS NOT NULL AND out_date_time IS NULL THEN ",
            "CASE ",
            "WHEN DATE ( add_date ) = CURDATE() AND HOUR (NOW()) &lt; 23 THEN TIMESTAMPDIFF( MINUTE, in_date_time, NOW()) ",
            "WHEN DATE ( add_date ) = CURDATE() AND HOUR ( NOW()) &gt;= 23 THEN 0 ELSE 0 END ELSE 0 END AS in_school_time ",
            "FROM",
            "xmy_erp_db.record_course AS t1 ",
            "LEFT JOIN xmy_erp_db.student_sign_in AS t2 ON t1.scheduling_detail_id = t2.scheduling_detail_id AND t1.student_id = t2.student_id AND t2.add_date = t1.school_date AND t2.subjects_id = t1.subjects_id",
            "WHERE ",
            "t1.school_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
            "AND t1.lesson_type = 3",
            "AND t1.subjects_id = ${subjectsId}",
            ") AS student_sign_in ",
            "GROUP BY ",
            "student_id ",
            ") t05 ON t05.student_id = t01.student_id AND t05.subjects_id = t01.subjects_id ",
            "LEFT JOIN tb_school_time_01 AS t07 ON t01.year_part = t07.year_part AND t01.quarter_num = t07.quarter_num AND t01.student_id = t07.student_id ",

//            "GROUP BY t01.student_id",
            ") AS t",
            "where 1=1",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 2'>",// 已通关
            " AND ((( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR ( brush_count_temp &gt;= 2 AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR ( not_brush = 1 AND ( right_num + amend_num ) &gt;= lowest_shutnum )) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
//                " AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND ( right_num + amend_num &gt;= lowest_shutnum ) AND lowest_shutnum &lt;&gt; 0 ",
//                " AND ( right_num + amend_num ) &gt;= lowest_shutnum AND lowest_shutnum &lt;&gt; 0",
//                " AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND lowest_shutnum &lt;&gt; 0",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 3'>",// 未通关
            " AND ((not_brush = 0 and brush_count_temp &lt;= 1 AND (right_num / lowest_shutnum )* 100 &lt; pass_rade ) OR (not_brush = 0 and brush_count_temp &gt;= 2 AND ( right_num + amend_num ) &lt; lowest_shutnum ) OR (( right_num / lowest_shutnum )* 100 &gt;= pass_rade  AND ( right_num + amend_num ) &lt; lowest_shutnum ) OR ( not_brush = 1 AND ( right_num + amend_num ) &lt; lowest_shutnum )) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
//                " AND ((( right_num / lowest_shutnum )* 100 &lt; pass_rade) OR ((right_num / lowest_shutnum * 100 &gt;= pass_rade) AND (right_num + amend_num &lt; lowest_shutnum))) AND lowest_shutnum &lt;&gt; 0 ",
//                " AND (  ( right_num + amend_num ) &lt; lowest_shutnum and lowest_shutnum &lt;&gt; 0)",
//                " AND (  ( right_num / lowest_shutnum )* 100 &lt; pass_rade and lowest_shutnum &lt;&gt; 0)",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 4'>",// 今日已通关
            " AND ((( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR ( brush_count_temp &gt;= 2 AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR (not_brush = 1 and ( right_num + amend_num ) &gt;= lowest_shutnum)) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
//                " AND ( right_num + amend_num ) &gt;= lowest_shutnum AND lowest_shutnum &lt;&gt; 0",
//                " AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND lowest_shutnum &lt;&gt; 0 ",
            "and add_date BETWEEN '${passDateStart}' AND '${passDateEnd}'",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 5'>",// 未刷（未完成）
            "and brush_count_temp = 0 AND (right_num =0 and amend_num=0  and lowest_shutnum is not null)",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 6'>", // 通关率——>需复刷
//                  "AND brush_count_temp &gt;= 1 AND brush_count_temp &lt;= 2 AND (right_num + amend_num) &lt; lowest_shutnum AND lowest_shutnum &lt;&gt; 0",
            "AND brush_count_temp &gt;= 1 AND (brush_count_temp &lt; 2 OR (right_num + amend_num &lt; lowest_shutnum)) AND ((( right_num / lowest_shutnum )* 100 &lt; pass_rade) OR ((right_num / lowest_shutnum * 100 &gt;= pass_rade) AND (right_num + amend_num &lt; lowest_shutnum))) AND lowest_shutnum &lt;&gt; 0",
//                "and brush_count_temp &gt;= 1 AND ((( right_num / lowest_shutnum )* 100 &lt; pass_rade ) and lowest_shutnum &lt;&gt; 0)",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 7'>",// 已完成详情
            "AND brush_count_temp &gt; 0 AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 8'>",// 根据日期已完成详情
            "AND brush_count_temp &gt; 0 AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL",
            "and add_date BETWEEN '${passDateStart}' AND '${passDateEnd}'",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 9'>",// 应复刷详情
            "AND is_first = 1  ",
            "AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade )",
            "AND lowest_shutnum &lt;&gt; 0 ",
            "AND lowest_shutnum IS NOT NULL ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 10'>",// 已复刷详情
            "AND is_first = 1 ",
            "AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade ) ",
            "AND lowest_shutnum &lt;&gt; 0 ",
            "AND lowest_shutnum IS NOT NULL ",
            "AND again_brush_id IS NOT NULL ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 11'>",// 根据日期已复刷详情
            "AND is_first = 1 ",
            "AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade ) ",
            "AND lowest_shutnum &lt;&gt; 0 ",
            "AND lowest_shutnum IS NOT NULL ",
            "AND again_brush_id IS NOT NULL ",
            "and add_date BETWEEN '${passDateStart}' AND '${passDateEnd}'",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 12'>",// 未复刷
            "AND is_first = 1  ",
            "AND (( right_num / lowest_shutnum )* 100 &lt; pass_rade )",
            "AND lowest_shutnum &lt;&gt; 0 ",
            "AND lowest_shutnum IS NOT NULL ",
            "AND again_brush_id IS NULL ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 13'>",// 应修正
            "AND brush_count_temp &gt;= 1 AND ( right_num + amend_num ) &lt; lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 14'>",// 已完成（正确+修正>=应通关）
            "AND brush_count_temp = 1 AND (right_num + amend_num) &gt;= lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 15'>",// 今日已完成（正确+修正>=应通关）
            "AND brush_count_temp = 1 AND (right_num + amend_num) &gt;= lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 16'>",// 需修正（第一次需修正）
            "AND brush_count_temp = 1 AND ( right_num + amend_num ) &lt; lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 17'>",// 复刷应通关
            "AND (brush_count_temp &gt;= 1 AND (brush_count_temp &lt; 2 OR ( right_num + amend_num &lt; lowest_shutnum )) AND (((right_num / lowest_shutnum )* 100 &lt; pass_rade ) OR (( right_num / lowest_shutnum * 100 &gt;= pass_rade ) AND ( right_num + amend_num &lt; lowest_shutnum ))) OR brush_count_temp &gt;= 2 ) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 18'>",// 复刷已通关
            "AND (( brush_count_temp &gt;= 2 AND (( right_num + amend_num ) &gt;= lowest_shutnum AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade ))) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 19'>",// 复刷未通关
            "AND ( brush_count_temp &gt;= 1 AND (( right_num + amend_num ) &lt; lowest_shutnum OR ( right_num / lowest_shutnum )* 100 &lt; pass_rade )) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 20'>",// 复刷今日已通关
            "AND (( brush_count_temp &gt;= 2 AND (( right_num + amend_num ) &gt;= lowest_shutnum AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade ))) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL",
            "AND add_date BETWEEN '${passDateStart}' AND '${passDateEnd}' ",
            "</when>",
            "<when test='studentIdStr!=null and studentIdStr!=&apos;&apos; '>",
            "AND student_id IN (${studentIdStr}) ",
            "</when>",
            "<when test='listState == 1 or listState == 2'>",
            "GROUP BY student_id",
            "</when>",
            "ORDER BY pass_date_time IS NULL ASC,pass_date_time ASC,student_id,lesson_num ASC",
            "</script>"})
    public IPage<ChaPlan> getPassedBrushiTeamDetail(IPage<?> page,
                                                @Param("yearPart") String yearPart,
                                                @Param("quarterNum") String quarterNum,
                                                @Param("schoolIdStr") String schoolIdStr,
                                                @Param("teacherId") String teacherId,
                                                @Param("yearClassIdStr") String yearClassIdStr,
                                                @Param("type") String type,
                                                @Param("gradeId") String gradeId,
                                                @Param("lessonNumStart") String lessonNumStart,
                                                @Param("lessonNum") String lessonNum,
                                                @Param("classTypeId") String classTypeId,
                                                @Param("readingType") String readingType,
                                                @Param("passType") String passType,
                                                @Param("lessonNow") String lessonNow,
                                                @Param("isAll") String isAll,
                                                @Param("courseVersionId") Long courseVersionId,
                                                @Param("passDate") String passDate,
                                                @Param("passDateStart") String passDateStart,
                                                @Param("passDateEnd") String passDateEnd,
                                                @Param("subjectsId") Long subjectsId,
                                                @Param("isBeforQuarter") String isBeforQuarter,
                                                @Param("readingStatusStr") String readingStatusStr,
                                                @Param("rightNumStartDate") String rightNumStartDate,
                                                @Param("rightNumEndDate") String rightNumEndDate,
                                                @Param("studentName") String studentName,
                                                @Param("radeType") String radeType,
                                                @Param("listState") String listState,
                                                @Param("classify") String classify,
                                                @Param("trackType") String trackType,
                                                @Param("teamId") String teamId,
                                                @Param("include") String include,
                                                @Param("inType") String inType,
                                                @Param("taskCategoryId") Integer taskCategoryId,
                                                @Param("courseSchedulingDetailName") String courseSchedulingDetailName,
                                                @Param("studentIdStr") String studentIdStr,
                                                @Param("moldType") String moldType, // 1正常通关率、2到勤通关率
                                                @Param("schoolDateStart") String schoolDateStart,
                                                @Param("schoolDateEnd") String schoolDateEnd,
                                                @Param("examSchedulingtType") String examSchedulingtType
    );


    @Select({"<script>",
            "SELECT",
            "*,",
            "( CASE WHEN brush_count_temp = 0 THEN 1 WHEN brush_count_temp &gt; 0 AND ( right_num + amend_num ) &gt;= lowest_shutnum THEN brush_count_temp + 1 ELSE brush_count_temp END ) AS brush_count,",
            "( CASE ",
            "WHEN brush_count_temp = 1 AND (right_num = 0 and amend_num = 0) THEN 0 ",
            "WHEN brush_count_temp &gt;= 1 AND ((( right_num / lowest_shutnum )* 100 &lt; pass_rade )) THEN 2 ",
            "ELSE 1 ",
            "END ) AS passType",
            "FROM",
            "(",
                "SELECT",
                "t01.id,",
                "t01.school_id,",
                "t01.year_part,",
                "t01.quarter_num,",
                "t02.course_version_id,",
                "t01.grade_id,",
                "t01.teacher_id,",
                "t01.class_type_id,",
                "t01.class_type_name,",
                "t01.year_class_id,",
                "t01.student_id,",
                "t02.task_course_num AS lesson_num,",
                "IFNULL( t03.brush_count, 1 ) AS brush_count_temp,",
                "IFNULL( t03.pass_rade, t02.pass_rade ) AS pass_rade,",
                "(CASE WHEN t03.right_num IS NOT NULL AND t03.pass_rade &gt; 0 AND ( right_num + amend_num ) &gt;= t03.lowest_shutnum AND ( t03.right_num / t03.lowest_shutnum )* 100 &gt;= t03.pass_rade THEN t03.lowest_shutnum ELSE t02.lowest_shutnum END ) AS lowest_shutnum,",
                "IFNULL( t03.right_num, 0 ) AS right_num,",
                "IFNULL( t03.amend_num, 0 ) AS amend_num,",
                "add_date ",
                "FROM",
                "(",
                    "SELECT",
                    "t1.*,",
                    "t1.class_type_id_new AS class_type_id,",
                    "t4.name as class_type_name,",
                    "t2.teacher_id ",
                    "FROM",
                    "xmy_erp_db.student_grade AS t1",
                    "LEFT JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id",
                    "LEFT JOIN per_student_account AS t3 ON t1.student_id = t3.student_id ",
                    "LEFT JOIN edu_class_type AS t4 ON t1.class_type_id_new = t4.id",
                    "WHERE",
                    "t1.year_part = ${yearPart} ",
                    "AND t1.quarter_num = ${quarterNum} ",
                    "AND t1.lesson_type = 1 ",
                    "AND t1.deleted = 0 ",
                    "AND t1.subjects_id = ${subjectsId} ",
                    "AND t1.reading_status IN (1,5) ",
                    "AND t1.STATUS &lt;&gt; 3 ",
                    "AND t1.student_id = ${studentId} ",
                    "AND t1.deleted = 0 ",
                    "GROUP BY",
                    "student_id ",
                ") AS t01",
                "LEFT JOIN ( ",
                    "SELECT * FROM edu_task WHERE  deleted = 0 and task_category_id=${taskCategoryId} and subjects_id = ${subjectsId} AND task_course_num &lt;= ${lessonNow}",
                    "<when test='yetLessonNumStr!=null and yetLessonNumStr!=&apos;&apos; '>",
                        "AND task_course_num IN (${yetLessonNumStr}) ",
                    "</when>",
                ") AS t02 ON t01.year_part = t02.year_part",
                "AND t01.quarter_num = t02.quarter_num ",
                "AND t01.subjects_id = t02.subjects_id ",
                "AND t01.class_type_id = t02.class_type_id ",
                "AND t01.year_class_id = t02.year_class_id",
                "LEFT JOIN (",
                    "SELECT",
                    "student_id,",
                    "add_date,",
                    "lesson_num_finish,",
                    "year_class_id,",
                    "course_version_id,",
                    "class_type_id,",
                    "year_part,",
                    "quarter_num,",
                    "IFNULL( lesson_num, 0 ) AS lesson_num,",
                    "right_num,",
                    "is_last,",
                    "amend_num,",
                    "lowest_shutnum,",
                    "brush_count,",
                    "pass_rade ",
                    "FROM",
                    "cha_plan ",
                    "WHERE",
                    "year_part = ${yearPart} ",
                    "AND quarter_num = ${quarterNum} ",
                    "AND task_category_id = ${taskCategoryId} ",
                    "and deleted =0",
                ") AS t03 ON t01.year_part = t03.year_part ",
                "AND t01.quarter_num = t03.quarter_num ",
                "AND t01.student_id = t03.student_id ",
                "AND t02.year_class_id = t03.year_class_id ",
                "AND t02.class_type_id = t03.class_type_id ",
                "AND t02.course_version_id = t03.course_version_id ",
                "AND t02.course_version_id = ${courseVersionId} ",
                "AND t01.subjects_id = ${subjectsId} ",
                "AND t02.task_course_num = t03.lesson_num ",
                "AND t03.is_last = 1 ",
            ") AS t ",
            "ORDER BY lesson_num,id DESC",
            "</script>"})
    public List<ChaPlan> getPassRadeDetailForStudentId(
            @Param("yearPart") String yearPart,
            @Param("quarterNum") String quarterNum,
            @Param("studentId") String studentId,
            @Param("courseVersionId") String courseVersionId,
            @Param("subjectsId") String subjectsId,
            @Param("lessonNow") String lessonNow,
            @Param("taskCategoryId") Integer taskCategoryId,
            @Param("yetLessonNumStr") String yetLessonNumStr
    );




    @Select("select * from cha_plan where year_part = ${yearPart} and quarter_num = ${quarterNum} and year_class_id =${yearClassId} and class_type_id =${classTypeId} and student_id = ${studentId} and lesson_num = ${lessonNum} and course_version_id = ${courseVersionId} and subjects_id = ${subjectsId} and deleted =0 ORDER BY id desc limit 1")
    public ChaPlan getLastOne(@Param("yearPart") Integer yearPart,
                              @Param("quarterNum") Integer quarterNum,
                              @Param("studentId") Long studentId,
                              @Param("yearClassId") Integer yearClassId,
                              @Param("classTypeId") Long classTypeId,
                              @Param("lessonNum") Integer lessonNum,
                              @Param("courseVersionId") Long courseVersionId,
                              @Param("subjectsId") Long subjectsId);

    @Select("select * from cha_plan where year_part = ${yearPart} and quarter_num = ${quarterNum} and year_class_id =${yearClassId} and class_type_id =${classTypeId} and student_id = ${studentId} and lesson_num = ${lessonNum} and lesson_num_finish = ${lessonNumFinish} and course_version_id = ${courseVersionId} and subjects_id = ${subjectsId} and deleted =0 ORDER BY id desc limit 1")
    public ChaPlan getOneForFinishNum(@Param("yearPart") Integer yearPart,
                              @Param("quarterNum") Integer quarterNum,
                              @Param("studentId") Long studentId,
                              @Param("yearClassId") Integer yearClassId,
                              @Param("classTypeId") Long classTypeId,
                              @Param("lessonNum") Integer lessonNum,
                              @Param("lessonNumFinish") Integer lessonNumFinish,
                              @Param("courseVersionId") Long courseVersionId,
                              @Param("subjectsId") Long subjectsId);

    @Select("select * from cha_plan where year_part = ${yearPart} and quarter_num = ${quarterNum} and task_category_id = ${taskCategoryId} and year_class_id =${yearClassId} and class_type_id =${classTypeId} and student_id = ${studentId} and lesson_num = ${lessonNum} and course_version_id = ${courseVersionId} and subjects_id = ${subjectsId} AND deleted = 0 ORDER BY id desc limit 1")
    public ChaPlan getOneForLessonNum(@Param("yearPart") Integer yearPart,
                                      @Param("quarterNum") Integer quarterNum,
                                      @Param("studentId") Long studentId,
                                      @Param("yearClassId") Integer yearClassId,
                                      @Param("classTypeId") Long classTypeId,
                                      @Param("lessonNum") Integer lessonNum,
                                      @Param("courseVersionId") Long courseVersionId,
                                      @Param("subjectsId") Long subjectsId,
                                      @Param("taskCategoryId") Integer taskCategoryId);


    @Update("update cha_plan set is_last = ${isLast} where year_part = ${yearPart} and quarter_num = ${quarterNum} and task_category_id =${taskCategoryId} and year_class_id =${yearClassId} and class_type_id =${classTypeId} and student_id = ${studentId} and lesson_num = ${lessonNum} and course_version_id = ${courseVersionId} and deleted=0 and subjects_id = ${subjectsId}")
    public boolean updateIsLast(@Param("yearPart") Integer yearPart,
                                @Param("quarterNum") Integer quarterNum,
                                @Param("studentId") Long studentId,
                                @Param("yearClassId") Integer yearClassId,
                                @Param("classTypeId") Long classTypeId,
                                @Param("lessonNum") Integer lessonNum,
                                @Param("isLast") Integer isLast,
                                @Param("courseVersionId") Long courseVersionId,
                                @Param("subjectsId") Long subjectsId,
                                @Param("taskCategoryId") Integer taskCategoryId
                                );

    @Update("update cha_plan set is_first = ${isFirst} where year_part = ${yearPart} and quarter_num = ${quarterNum} and task_category_id =${taskCategoryId} and year_class_id =${yearClassId} and class_type_id =${classTypeId} and student_id = ${studentId} and lesson_num = ${lessonNum} and course_version_id = ${courseVersionId} and subjects_id = ${subjectsId} and deleted=0")
    public boolean updateIsFirst(@Param("yearPart") Integer yearPart,
                                @Param("quarterNum") Integer quarterNum,
                                @Param("studentId") Long studentId,
                                @Param("yearClassId") Integer yearClassId,
                                @Param("classTypeId") Long classTypeId,
                                @Param("lessonNum") Integer lessonNum,
                                @Param("isFirst") Integer isFirst,
                                @Param("courseVersionId") Long courseVersionId,
                                @Param("subjectsId") Long subjectsId,
                                @Param("taskCategoryId") Integer taskCategoryId
    );

    @Update("update cha_plan set is_finish = ${isFinish} where year_part = ${yearPart} and quarter_num = ${quarterNum} and task_category_id = ${taskCategoryId} and year_class_id =${yearClassId} and class_type_id =${classTypeId} and student_id = ${studentId} and lesson_num = ${lessonNum} and course_version_id = ${courseVersionId} and subjects_id = ${subjectsId} and deleted=0")
    public boolean updateIsFinish(@Param("yearPart") Integer yearPart,
                                @Param("quarterNum") Integer quarterNum,
                                @Param("studentId") Long studentId,
                                @Param("yearClassId") Integer yearClassId,
                                @Param("classTypeId") Long classTypeId,
                                @Param("lessonNum") Integer lessonNum,
                                @Param("isFinish") Integer isFinish,
                                @Param("courseVersionId") Long courseVersionId,
                                @Param("subjectsId") Long subjectsId,
                                @Param("taskCategoryId") Long taskCategoryId
                                  );

    @Select({"<script>",
            "SELECT",
                        "*,",
                        "( not_pass_num_temp - store_count ) AS draw_up_count ",
                    "FROM",
                        "(",
                        "SELECT",
                          "school_id,",
                          "year_part,",
                          "quarter_num,",
                          "grade_id,",
                          "teacher_id,",
                          "class_type_id,",
                          "year_class_id,",
                          "student_id,",
                          "lesson_num,",
                        "IF",
                          "( brush_count = 0, 1, brush_count ) AS brush_count,",
                          "add_date,",
                          "SUM( lowest_shutnum ) AS lowest_shutnum,",
                          "pass_rade,",
                          "0 AS right_num_date_no_sum,",
                          "SUM( right_num ) AS right_num,",
                          "SUM( amend_num ) AS amend_num,",
                          "SUM( CASE WHEN lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL THEN 1 ELSE 0 END ) AS student_all_shutnum,",
                          "SUM( CASE WHEN is_yet &gt; 0 THEN 1 ELSE 0 END ) AS yet_pass_num_temp,",
                          "SUM( CASE WHEN is_not &gt; 0 THEN 1 ELSE 0 END ) AS not_pass_num_temp,",
                          "store_count ",
                        "FROM",
                          "(",
                          "SELECT",
                            "school_id,",
                            "year_part,",
                            "quarter_num,",
                            "course_version_id,",
                            "grade_id,",
                            "teacher_id,",
                            "class_type_id,",
                            "year_class_id,",
                            "student_id,",
                            "lesson_num,",
                            "brush_count,",
                            "add_date,",
                            "lowest_shutnum,",
                            "right_num,",
                            "amend_num,",
                            "pass_rade,",
                            "( CASE WHEN ( ( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ) THEN 1 ELSE 0 END ) AS is_yet,",
                            "( CASE WHEN ( ( right_num / lowest_shutnum )* 100 &lt; pass_rade ) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL THEN 1 ELSE 0 END ) AS is_not,",
                            "( goods_count + prestore_count ) AS store_count ",
                          "FROM",
                            "(",
                            "SELECT",
                              "t1.school_id,",
                              "t1.student_id,",
                              "t1.subjects_id,",
                              "t1.year_part,",
                              "t1.quarter_num,",
                              "t1.grade_id,",
                              "t2.teacher_id,",
                              "t2.course_type_id AS class_type_id,",
                              "et.course_version_id,",
                              "t2.year_class_id,",
                              "et.task_course_num AS lesson_num,",
                              "t4.add_date,",
                              "IFNULL( t4.brush_count, 0 ) AS brush_count,",
                              "(",
                              "CASE",
                                  "WHEN t4.right_num IS NOT NULL ",
                                  "AND t4.pass_rade > 0 ",
                                  "AND ( t4.right_num + t4.amend_num ) &gt;= t4.lowest_shutnum ",
                                  "AND ( t4.right_num / t4.lowest_shutnum )* 100 &gt;= t4.pass_rade THEN",
                                      "t4.lowest_shutnum ELSE et.lowest_shutnum ",
                                  "END ",
                                  ") AS lowest_shutnum,",
                                  "IFNULL( t4.right_num, 0 ) AS right_num,",
                                  "IFNULL( t4.amend_num, 0 ) AS amend_num,",
                                  "IFNULL( t4.pass_rade, et.pass_rade ) AS pass_rade,",
                                  "IFNULL( sg.goods_count, 0 ) AS goods_count,",
                                  "IFNULL( sg.prestore_count, 0 ) AS prestore_count ",
                                "FROM",
                                  "xmy_erp_db.student_grade AS t1",
                                  "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id",
                                  "INNER JOIN per_student_account AS t3 ON t1.student_id = t3.student_id",
                                  "LEFT JOIN edu_task AS et ON t1.year_part = et.year_part ",
                                  "AND t1.quarter_num = et.quarter_num ",
                                  "AND t1.subjects_id = et.subjects_id ",
                                  "AND t2.course_type_id = et.class_type_id ",
                                  "AND t2.year_class_id = et.year_class_id ",
                                  "AND t1.subjects_id = et.subjects_id ",
                                  "AND t1.deleted = et.deleted ",
                                  "AND et.task_course_num BETWEEN ${startLessonNum} AND ${endLessonNum}",
                                  "AND et.task_category_id = ${taskCategoryId}",
                                  "LEFT JOIN cha_plan AS t4 ON t1.year_part = t4.year_part ",
                                  "AND t1.quarter_num = t4.quarter_num ",
                                  "AND t1.student_id = t4.student_id ",
                                  "AND t1.year_class_id = t4.year_class_id ",
                                  "AND t1.subjects_id = t4.subjects_id ",
                                  "AND et.course_version_id = t4.course_version_id ",
                                  "AND et.class_type_id = t4.class_type_id ",
                                  "AND et.task_course_num = t4.lesson_num ",
                                  "AND et.task_category_id = t4.task_category_id ",
                                  "AND t4.is_last = 1",
                                  "and t4.deleted =0",
                                  "LEFT JOIN xmy_erp_db.store_goods AS sg ON t1.school_id = sg.school_id ",
                                  "AND t1.subjects_id = sg.subjects_id ",
                                  "AND t1.year_part = sg.year_part ",
                                  "AND t1.quarter_num = sg.quarter_num ",
                                  "AND t2.course_type_id = sg.class_type_id ",
                                  "AND t1.year_class_id = sg.year_class_id ",
                                  "AND t1.deleted = sg.deleted ",
                                  "AND sg.goods_type_id = ${goodsTypeId} ",
                                  "and sg.lesson_num = et.task_course_num",
                                  "and sg.lesson_type = 3",
                                "WHERE",
                                  "t1.year_part = ${yearPart} ",
                                  "and t1.school_id = ${schoolId}",
                                  "AND t1.quarter_num = ${quarterNum} ",
                                  "AND t1.lesson_type = ${lessonType} ",
                                  "AND t1.deleted = 0 ",
                                  "AND t1.subjects_id = ${subjectsId} ",
                                  "AND t1.is_last = 1 ",
                                  "AND ((",
                                        "t1.reading_status IN ( 1, 5 )) ",
                                  "OR ( t1.reading_status IN ( 3, 4 ) AND t1.use_course_count &gt; 0 )) ",
                                  "AND t1.STATUS &lt;&gt; 3 ",
                                  "AND t1.deleted = 0 ",
                                  "AND t2.year_class_id &lt; 13 ",
                                    "<when test='classTypeId!=null and classTypeId!=&apos;&apos;'>",
                                        "and t1.class_type_id_new = ${classTypeId}",
                                    "</when>",
                                    "<when test='yearClassId!=null and yearClassId!=&apos;&apos;'>",
                                        "and t2.year_class_id = ${yearClassId}",
                                    "</when>",
                                ") AS t01 ",
                              ") AS t ",
                            "GROUP BY",
                              "school_id,",
                              "class_type_id,",
                              "year_class_id,",
                              "lesson_num ",
                            ") AS tt ",
                          "WHERE",
                            "1 = 1 ",
                            "AND lesson_num IS NOT NULL ",
                        "ORDER BY",
                        "school_id ASC",
            "</script>"})
    public List<ChaPlan> getNeedOrder(@Param("yearPart") Integer yearPart,
                                       @Param("quarterNum") Integer quarterNum,
                                       @Param("schoolId") Long schoolId,
                                       @Param("yearClassId") String yearClassId,
                                       @Param("classTypeId") Long classTypeId,
                                       @Param("subjectsId") Long subjectsId,
                                       @Param("lessonType") Integer lessonType,
                                       @Param("goodsTypeId") Long goodsTypeId,
                                       @Param("startLessonNum") Integer startLessonNum,
                                       @Param("endLessonNum") Integer endLessonNum,
                                      @Param("taskCategoryId") Integer taskCategoryId);


    @Select({"<script>",
            "SELECT",
                    "CAST(FLOOR(RAND() * 100000000000) AS UNSIGNED) AS id,",
                    "tt.year_part,",
                    "tt.quarter_num,",
                    "tt.school_id,",
                    "tt.year_class_id,",
                    "tt.class_type_id,",
                    "sch.`name` as school_name,",
                    "ct.name as class_type_name",
                    "FROM",
                        "(",
                        "SELECT",
                          "school_id,",
                          "year_part,",
                          "quarter_num,",
                          "grade_id,",
                          "teacher_id,",
                          "class_type_id,",
                          "year_class_id,",
                          "student_id,",
                          "lesson_num,",
                        "IF",
                          "( brush_count = 0, 1, brush_count ) AS brush_count,",
                          "add_date,",
                          "SUM( lowest_shutnum ) AS lowest_shutnum,",
                          "pass_rade,",
                          "0 AS right_num_date_no_sum,",
                          "SUM( right_num ) AS right_num,",
                          "SUM( amend_num ) AS amend_num,",
                          "SUM( CASE WHEN lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL THEN 1 ELSE 0 END ) AS student_all_shutnum,",
                          "SUM( CASE WHEN is_yet &gt; 0 THEN 1 ELSE 0 END ) AS yet_pass_num_temp,",
                          "SUM( CASE WHEN is_not &gt; 0 THEN 1 ELSE 0 END ) AS not_pass_num_temp,",
                          "store_count ",
                        "FROM",
                          "(",
                          "SELECT",
                            "school_id,",
                            "year_part,",
                            "quarter_num,",
                            "course_version_id,",
                            "grade_id,",
                            "teacher_id,",
                            "class_type_id,",
                            "year_class_id,",
                            "student_id,",
                            "lesson_num,",
                            "brush_count,",
                            "add_date,",
                            "lowest_shutnum,",
                            "right_num,",
                            "amend_num,",
                            "pass_rade,",
                            "( CASE WHEN ( ( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ) THEN 1 ELSE 0 END ) AS is_yet,",
                            "( CASE WHEN ( ( right_num / lowest_shutnum )* 100 &lt; pass_rade ) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL THEN 1 ELSE 0 END ) AS is_not,",
                            "( goods_count + prestore_count ) AS store_count ",
                          "FROM",
                            "(",
                            "SELECT",
                              "t1.school_id,",
                              "t1.student_id,",
                              "t1.subjects_id,",
                              "t1.year_part,",
                              "t1.quarter_num,",
                              "t1.grade_id,",
                              "t2.teacher_id,",
                              "t2.course_type_id AS class_type_id,",
                              "et.course_version_id,",
                              "t2.year_class_id,",
                              "et.task_course_num AS lesson_num,",
                              "t4.add_date,",
                              "IFNULL( t4.brush_count, 0 ) AS brush_count,",
                              "(",
                              "CASE",
                                  "WHEN t4.right_num IS NOT NULL ",
                                  "AND t4.pass_rade > 0 ",
                                  "AND ( t4.right_num + t4.amend_num ) &gt;= t4.lowest_shutnum ",
                                  "AND ( t4.right_num / t4.lowest_shutnum )* 100 &gt;= t4.pass_rade THEN",
                                      "t4.lowest_shutnum ELSE et.lowest_shutnum ",
                                  "END ",
                                  ") AS lowest_shutnum,",
                                  "IFNULL( t4.right_num, 0 ) AS right_num,",
                                  "IFNULL( t4.amend_num, 0 ) AS amend_num,",
                                  "IFNULL( t4.pass_rade, et.pass_rade ) AS pass_rade,",
                                  "IFNULL( sg.goods_count, 0 ) AS goods_count,",
                                  "IFNULL( sg.prestore_count, 0 ) AS prestore_count ",
                                "FROM",
                                  "xmy_erp_db.student_grade AS t1",
                                  "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id",
                                  "INNER JOIN per_student_account AS t3 ON t1.student_id = t3.student_id",
                                  "LEFT JOIN edu_task AS et ON t1.year_part = et.year_part ",
                                  "AND t1.quarter_num = et.quarter_num ",
                                  "AND t1.subjects_id = et.subjects_id ",
                                  "AND t2.course_type_id = et.class_type_id ",
                                  "AND t2.year_class_id = et.year_class_id ",
                                  "AND t1.subjects_id = et.subjects_id ",
                                  "AND t1.deleted = et.deleted ",
                                  "AND et.task_course_num BETWEEN ${startLessonNum} AND ${endLessonNum}",
                                  "AND et.task_category_id = ${taskCategoryId}",
                                  "LEFT JOIN cha_plan AS t4 ON t1.year_part = t4.year_part ",
                                  "AND t1.quarter_num = t4.quarter_num ",
                                  "AND t1.student_id = t4.student_id ",
                                  "AND t1.year_class_id = t4.year_class_id ",
                                  "AND t1.subjects_id = t4.subjects_id ",
                                  "AND et.course_version_id = t4.course_version_id ",
                                  "AND et.class_type_id = t4.class_type_id ",
                                  "AND et.task_course_num = t4.lesson_num ",
                                  "AND et.task_category_id = t4.task_category_id ",
                                  "AND t4.is_last = 1",
                                  "AND t4.deleted = 0",
                                  "LEFT JOIN xmy_erp_db.store_goods AS sg ON t1.school_id = sg.school_id ",
                                  "AND t1.subjects_id = sg.subjects_id ",
                                  "AND t1.year_part = sg.year_part ",
                                  "AND t1.quarter_num = sg.quarter_num ",
                                  "AND t2.course_type_id = sg.class_type_id ",
                                  "AND t1.year_class_id = sg.year_class_id ",
                                  "AND t1.deleted = sg.deleted ",
                                  "AND sg.goods_type_id = ${goodsTypeId} ",
                                  "and sg.lesson_num = et.task_course_num",
                                "WHERE",
                                  "t1.year_part = ${yearPart} ",
                                  "and t1.school_id = ${schoolId}",
                                  "AND t1.quarter_num = ${quarterNum} ",
                                  "AND t1.lesson_type = ${lessonType} ",
                                  "AND t1.deleted = 0 ",
                                  "AND t1.subjects_id = ${subjectsId} ",
                                  "AND t1.is_last = 1 ",
                                  "AND ((",
                                        "t1.reading_status IN ( 1, 5 )) ",
                                  "OR ( t1.reading_status IN ( 3, 4 ) AND t1.use_course_count &gt; 0 )) ",
                                  "AND t1.STATUS &lt;&gt; 3 ",
                                  "AND t1.deleted = 0 ",
                                  "AND t2.year_class_id &lt; 13 ",
                                    "<when test='yearClassId!=null and yearClassId!=&apos;&apos;'>",
                                    "and t2.year_class_id = ${yearClassId}",
                                    "</when>",
                                    "<when test='classTypeId!=null and classTypeId!=&apos;&apos;'>",
                                    "and t1.class_type_id_new = ${classTypeId}",
                                    "</when>",
                                ") AS t01 ",
                              ") AS t ",
                            "GROUP BY",
                              "school_id,",
                              "class_type_id,",
                              "year_class_id,",
                              "lesson_num ",
                            ") AS tt ",
                            "INNER JOIN adm_organization as sch on tt.school_id = sch.id",
                            "INNER JOIN edu_class_type as ct on tt.class_type_id = ct.id",
                          "WHERE",
                            "1 = 1 ",
                            "AND tt.lesson_num IS NOT NULL ",
                            "GROUP BY",
                            "tt.school_id,",
                            "tt.year_class_id,",
                            "tt.class_type_id ",
                        "ORDER BY",
                        "tt.school_id ASC",
            "</script>"})
    public IPage<StoreData> getNeedOrderForGroup(
                                       IPage<?> page,
                                       @Param("yearPart") Integer yearPart,
                                       @Param("quarterNum") Integer quarterNum,
                                       @Param("schoolId") Long schoolId,
                                       @Param("yearClassId") String yearClassId,
                                       @Param("classTypeId") Long classTypeId,
                                       @Param("subjectsId") Long subjectsId,
                                       @Param("lessonType") Integer lessonType,
                                       @Param("goodsTypeId") Long goodsTypeId,
                                       @Param("startLessonNum") Integer startLessonNum,
                                       @Param("endLessonNum") Integer endLessonNum,
                                       @Param("taskCategoryId") Integer taskCategoryId);


    //查出未通关课次
    @Select({"<script>",
            "SELECT",
            "GROUP_CONCAT( lesson_num) as lesson_num_str",
            "FROM",
            "(",
            "SELECT",
            "t01.id,",
            "t01.school_id,",
            "t01.year_part,",
            "t01.quarter_num,",
            "t02.course_version_id,",
            "t01.grade_id,",
            "t01.teacher_id,",
            "t01.class_type_id,",
            "t01.year_class_id,",
            "t01.student_id,",
            "t02.task_course_num AS lesson_num,",
            "IFNULL( t03.brush_count, 0 ) AS brush_count_temp,",
            "IFNULL( t03.pass_rade, t02.pass_rade ) AS pass_rade,",
            "(",
            "CASE",
            "WHEN t03.right_num IS NOT NULL ",
            "AND t03.pass_rade &gt; 0 ",
            "AND ( right_num + amend_num ) &gt;= t03.lowest_shutnum ",
            "AND ( t03.right_num / t03.lowest_shutnum )* 100 &gt;= t03.pass_rade THEN",
            "t03.lowest_shutnum ELSE t02.lowest_shutnum ",
            "END ",
            ") AS lowest_shutnum,",
            "IFNULL( t03.right_num, 0 ) AS right_num,",
            "IFNULL( t03.amend_num, 0 ) AS amend_num,",
            "add_date ",
            "FROM",
            "(",
            "SELECT",
            "t1.*,",
            "t1.class_type_id_new AS class_type_id,",
            "t2.teacher_id ",
            "FROM",
            "xmy_erp_db.student_grade AS t1",
            "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id",
            "INNER JOIN per_student_account AS t3 ON t1.student_id = t3.student_id",
                    "LEFT JOIN xmy_erp_db.rade_exclude_student AS t4 ON t4.classify_id = 0 ",
                    "AND t4.deleted = 0 ",
                    "AND t4.type = 2 ",
                    "AND t1.student_id = t4.student_id ",
                    "AND t1.year_part = t4.year_part ",
                    "AND t1.quarter_num = t4.quarter_num ",
                    "AND ( FIND_IN_SET( t1.subjects_id, t4.subjects_ids ) OR t4.subjects_ids IS NULL ) ",
                    "AND ( FIND_IN_SET( t1.school_id, t4.school_ids ) OR t4.school_ids IS NULL ) ",
            "WHERE",
            "t1.year_part = ${rs.yearPart} ",
            "AND t1.quarter_num = ${rs.quarterNum} ",
            "AND t1.lesson_type = 1 ",
            "AND t1.deleted = 0 ",
            "<when test='rs.subjectsId!=null and rs.subjectsId!=&apos;&apos; '>",
            "and t1.subjects_id = ${rs.subjectsId} ",
            "</when>",
            "AND t1.is_last = 1 ",
            "<when test='rs.include!=null and rs.include!=&apos;&apos;'>",
            "<when test='rs.include == 0'>",
            "and t4.id is null ",
            "</when>",
            "<when test='rs.include == 1'>",
            "and t4.id is not null ",
            "</when>",
            "</when>",
            "AND ((",
            "t1.reading_status IN ( 1, 5 )) ",
            "OR ( t1.reading_status IN ( 3, 4 ) AND use_course_count &gt; 0 )) ",
            "AND t1.`status` &lt;&gt; 3 ",
            "AND t1.deleted = 0 ",
            "AND t1.grade_id = ${rs.gradeId} ",
            "AND t2.year_class_id = ${rs.yearClassId} ",
            "AND t2.teacher_id = ${rs.teacherId} ",
            "GROUP BY",
            "student_id ",
            ") AS t01",
            "LEFT JOIN ( SELECT * FROM edu_task WHERE deleted = 0 ",
            "<when test='rs.subjectsId!=null and rs.subjectsId!=&apos;&apos; '>",
            "and subjects_id = ${rs.subjectsId} ",
            "</when>",
            "and task_category_id = ${rs.taskCategoryId}",
            "AND task_course_num BETWEEN ${rs.lessonNumStart} AND ${rs.lessonNum} ) AS t02 ON t01.year_part = t02.year_part ",
            "AND t01.quarter_num = t02.quarter_num ",
            "AND t01.subjects_id = t02.subjects_id ",
            "AND t01.class_type_id = t02.class_type_id ",
            "AND t01.year_class_id = t02.year_class_id",
            "LEFT JOIN (",
            "SELECT",
            "student_id,",
            "add_date,",
            "lesson_num_finish,",
            "year_class_id,",
            "course_version_id,",
            "class_type_id,",
            "year_part,",
            "quarter_num,",
            "IFNULL( lesson_num, 0 ) AS lesson_num,",
            "right_num,",
            "is_last,",
            "is_first,",
            "amend_num,",
            "lowest_shutnum,",
            "brush_count,",
            "pass_rade ",
            "FROM",
            "cha_plan ",
            "WHERE",
            "year_part = ${rs.yearPart} ",
            "AND quarter_num = ${rs.quarterNum} ",
            "AND task_category_id = ${rs.taskCategoryId} ",
            "and deleted = 0",
            ") AS t03 ON t01.year_part = t03.year_part ",
            "AND t01.quarter_num = t03.quarter_num ",
            "AND t01.student_id = t03.student_id ",
            "AND t02.year_class_id = t03.year_class_id ",
            "AND t02.class_type_id = t03.class_type_id ",
            "AND t02.course_version_id = t03.course_version_id ",
            "AND t02.course_version_id = ${rs.courseVersionId} ",
            "<when test='rs.subjectsId!=null and rs.subjectsId!=&apos;&apos; '>",
            "and t01.subjects_id = ${rs.subjectsId} ",
            "</when>",
            "AND t02.task_course_num = t03.lesson_num ",
            "AND t03.is_last = 1 ",
            ") AS t ",
            "WHERE",
            "student_id = ${rs.studentId}",
//            "( ( right_num / lowest_shutnum )* 100 &lt; pass_rade AND lowest_shutnum &lt;&gt; 0  AND student_id = ${rs.studentId}) ",
            "<when test='rs.passType!=null and rs.passType!=&apos;&apos; and rs.passType == 2'>",// 已通关
            " AND ((( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR ( brush_count_temp &gt;= 2 AND ( right_num + amend_num ) &gt;= lowest_shutnum )) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "</when>",
            "<when test='rs.passType!=null and rs.passType!=&apos;&apos; and rs.passType == 3'>",// 未通关
            " AND ((brush_count_temp &lt;= 1 AND (right_num / lowest_shutnum )* 100 &lt; pass_rade ) OR ( brush_count_temp &gt;= 2 AND ( right_num + amend_num ) &lt; lowest_shutnum ) OR (( right_num / lowest_shutnum )* 100 &gt;= pass_rade  AND ( right_num + amend_num ) &lt; lowest_shutnum ) ) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "</when>",
            "<when test='rs.passType!=null and rs.passType!=&apos;&apos; and rs.passType == 4'>",// 今日已通关
            " AND ((( right_num / lowest_shutnum )* 100 &gt;= pass_rade AND ( right_num + amend_num ) &gt;= lowest_shutnum ) OR ( brush_count_temp &gt;= 2 AND ( right_num + amend_num ) &gt;= lowest_shutnum )) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "and add_date BETWEEN '${rs.passDateStart}' AND '${rs.passDateEnd}'",
            "</when>",
            "<when test='rs.passType!=null and rs.passType!=&apos;&apos; and rs.passType == 5'>",
            "and brush_count_temp = 0 AND (right_num =0 and amend_num=0  and lowest_shutnum is not null)",
            "</when>",
            "<when test='rs.passType!=null and rs.passType!=&apos;&apos; and rs.passType == 6'>",
            "and brush_count_temp &gt;= 1 AND (brush_count_temp &lt; 2 OR (right_num + amend_num &lt; lowest_shutnum)) AND ((( right_num / lowest_shutnum )* 100 &lt; pass_rade ) OR ((right_num / lowest_shutnum * 100 &gt;= pass_rade ) AND ( right_num + amend_num &lt; lowest_shutnum )))",
            "</when>",
            "<when test='rs.passType!=null and rs.passType!=&apos;&apos; and rs.passType == 13'>",// 应修正
                "AND brush_count_temp &gt;= 1 AND ( right_num + amend_num ) &lt; lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "</when>",
            "<when test='rs.passType!=null and rs.passType!=&apos;&apos; and rs.passType == 14'>",// 已完成（正确+修正>=应通关）
                "AND brush_count_temp = 1 AND (right_num + amend_num) &gt;= lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "</when>",
            "<when test='rs.passType!=null and rs.passType!=&apos;&apos; and rs.passType == 15'>",// 今日已完成（正确+修正>=应通关）
                "AND brush_count_temp = 1 AND (right_num + amend_num) &gt;= lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
                "AND add_date BETWEEN '${rs.passDateStart}' AND '${rs.passDateEnd}'",
            "</when>",
            "<when test='rs.passType!=null and rs.passType!=&apos;&apos; and rs.passType == 16'>",// 需修正（第一次需修正）
                "AND brush_count_temp = 1 AND ( right_num + amend_num ) &lt; lowest_shutnum AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "</when>",
            "<when test='rs.passType!=null and rs.passType!=&apos;&apos; and rs.passType == 17'>",// 复刷应通关
                "AND (brush_count_temp &gt;= 1 AND (brush_count_temp &lt; 2 OR ( right_num + amend_num &lt; lowest_shutnum )) AND (((right_num / lowest_shutnum )* 100 &lt; pass_rade ) OR (( right_num / lowest_shutnum * 100 &gt;= pass_rade ) AND ( right_num + amend_num &lt; lowest_shutnum ))) OR brush_count_temp &gt;= 2 ) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "</when>",
            "<when test='rs.passType!=null and rs.passType!=&apos;&apos; and rs.passType == 18'>",// 复刷已通关
                "AND (( brush_count_temp &gt;= 2 AND (( right_num + amend_num ) &gt;= lowest_shutnum AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade ))) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL",
            "</when>",
            "<when test='rs.passType!=null and rs.passType!=&apos;&apos; and rs.passType == 19'>",// 复刷未通关
                "AND ( brush_count_temp &gt;= 1 AND (( right_num + amend_num ) &lt; lowest_shutnum OR ( right_num / lowest_shutnum )* 100 &lt; pass_rade )) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL ",
            "</when>",
            "<when test='rs.passType!=null and rs.passType!=&apos;&apos; and rs.passType == 20'>",// 复刷今日已通关
                "AND (( brush_count_temp &gt;= 2 AND (( right_num + amend_num ) &gt;= lowest_shutnum AND ( right_num / lowest_shutnum )* 100 &gt;= pass_rade ))) AND lowest_shutnum &lt;&gt; 0 AND lowest_shutnum IS NOT NULL",
                "AND add_date BETWEEN '${rs.passDateStart}' AND '${rs.passDateEnd}'",
            "</when>",
            "ORDER BY",
            "lesson_num,",
            "id ASC ",
            "</script>"})
    public String getChaPlanLessonNumString(@Param("rs") ChaPlan chaPlan);


    /**
     * 荣誉榜单列表
     */
    @Select({"<script>",
            "SELECT",
            "<when test='type == 6'>",
                "t01.pid AS schoolPid,",
                "t01.school_name,",
                "t01.school_id,",
            "</when>",
            "<when test='type != 6'>",
                "diff01.school_id,",
            "</when>",
            "teacher_id,",
            "teacher_name,",
            "diff01.year_part,",
            "diff01.quarter_num,",
            "COUNT(student_id) AS showPassNum,",
            "SUM( CASE WHEN right_rade &lt; right_rade2 THEN 1 ELSE 0 END ) AS ordinary_count,",
            "SUM( CASE WHEN right_rade &gt;= right_rade2 THEN 1 ELSE 0 END ) AS progress_count,",
            "SUM( CASE WHEN right_rade &gt;= 90 THEN 1 ELSE 0 END ) AS excellent_count,",
            "SUM( CASE WHEN right_rade &gt;= 100 THEN 1 ELSE 0 END ) AS apex_count, ",
            "SUM( CASE WHEN right_rade &lt; right_rade2 AND add_date BETWEEN '${startDate}' AND '${endDate}' THEN 1 ELSE 0 END ) AS ordinary_num,",
            "SUM( CASE WHEN right_rade &gt;= right_rade2 AND add_date BETWEEN '${startDate}' AND '${endDate}' THEN 1 ELSE 0 END ) AS progress_num,",
            "SUM( CASE WHEN right_rade &gt;= 90 AND add_date BETWEEN '${startDate}' AND '${endDate}' THEN 1 ELSE 0 END ) AS excellent_num,",
            "SUM( CASE WHEN right_rade &gt;= 100 AND add_date BETWEEN '${startDate}' AND '${endDate}' THEN 1 ELSE 0 END ) AS apex_num ",
            "<when test='type == 6'>",
                "FROM ( SELECT * FROM xmy_erp_db.school_quarter WHERE year_part = ${yearPart} AND quarter_num = ${quarterNum} AND deleted = 0) AS t01",
                "LEFT JOIN (",
            "</when>",
                "<when test='type != 6'>",
            "FROM (" ,
            "</when>",
                "SELECT ",
                "diff1.*,",
                "diff2.lowest_shutnum AS lowest_shutnum2, ",
                "diff2.right_num AS right_num2,",
                "diff2.amend_num AS amend_num2,",
                "ROUND((( diff1.right_num / diff1.lowest_shutnum )* 100 ), 2 ) AS right_rade, ",
                "ROUND((( diff2.right_num / diff2.lowest_shutnum )* 100 ), 2 ) AS right_rade2 ",
                "FROM ( ",
                    "SELECT ",
                    "t01.school_id,",
                    "t01.year_part,",
                    "t01.quarter_num,",
                    "t02.course_version_id,",
                    "t01.grade_id,",
                    "t01.grade_name,",
                    "t01.teacher_id,",
                    "t01.teacher_name,",
                    "t01.class_type_id,",
                    "t01.year_class_id,",
                    "t01.student_id,",
                    "t02.task_course_num AS lesson_num,",
                    "t03.is_first,",
                    "t03.is_last,",
                    "t03.add_date, ",
                    "IFNULL( t03.brush_count, 0 ) AS brush_count,",
                    "(CASE WHEN t03.right_num IS NOT NULL AND t03.pass_rade &gt; 0 AND ( t03.right_num + t03.amend_num ) &gt;= t03.lowest_shutnum AND ( t03.right_num / t03.lowest_shutnum )* 100 &gt;= t03.pass_rade THEN t03.lowest_shutnum ELSE t02.lowest_shutnum END ) AS lowest_shutnum,",
                    "IFNULL( t03.right_num, 0 ) AS right_num, ",
                    "IFNULL( t03.amend_num, 0 ) AS amend_num ",
                    "FROM ( ",
                        "SELECT",
                        "t1.*,",
                        "t1.class_type_id_new as class_type_id,",
                        "t2.teacher_id,",
                        "t2.`name` AS grade_name,",
                        "sff.`name` AS teacher_name",
                        "FROM",
                        "xmy_erp_db.student_grade AS t1",
                        "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id ",
                        "INNER JOIN xmy_erp_db.staff AS sff ON sff.id = t2.teacher_id",
                        "INNER JOIN per_student_account AS t3 ON t1.student_id = t3.student_id",
                        "LEFT JOIN xmy_erp_db.rade_exclude_student AS t4 ON t4.classify_id = 0 AND t4.deleted = 0 AND t4.type = 2 AND t1.student_id = t4.student_id AND t1.year_part = t4.year_part AND t1.quarter_num = t4.quarter_num AND ( FIND_IN_SET( t1.subjects_id, t4.subjects_ids ) OR t4.subjects_ids IS NULL ) AND ( FIND_IN_SET( t1.school_id, t4.school_ids ) OR t4.school_ids IS NULL ) ",
                        "WHERE",
                        "t1.year_part = ${yearPart} ",
                        "AND t1.quarter_num = ${quarterNum} ",
                        "AND t1.lesson_type = 1 ",
                        "AND t1.deleted = 0 ",
                        "AND t1.subjects_id IN (${subjectsId}) ",
                        "AND t1.is_last = 1 ",
                        "<when test='include!=null and include!=&apos;&apos;'>",
                            "<when test='include == 0'>",
                                "and t4.id is null ",
                            "</when>",
                            "<when test='include == 1'>",
                                "and t4.id is not null ",
                            "</when>",
                        "</when>",
                        "<when test='isBeforQuarter == 0 and readingType == 1'>",
                            "AND t1.reading_status IN (1,5) ",
                        "</when>",
                        "<when test='isBeforQuarter == 1 and readingType == 1'>",
                            "AND t1.reading_status IN (1,5)",
                        "</when>",
                        "<when test='readingType == 2'>",
                            "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and use_course_count &gt; 0)) ",
                        "</when>",
                        "AND t1.STATUS &lt;&gt; 3 ",
                        "AND t1.deleted = 0 ",

                        "<when test='schoolIdStr!=null and schoolIdStr!=&apos;&apos; and (type == 2 || type == 4)'>",
                            "AND t1.school_id in(${schoolIdStr}) ",
                        "</when>",
                        "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
                            "AND t2.teacher_id in(${teacherId}) ",
                        "</when>",
                        "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
                            "AND t2.year_class_id in(${yearClassIdStr}) ",
                        "</when>",
                        "<when test='yearClassIdStr==null or yearClassIdStr==&apos;&apos; '>",
                            "AND t2.year_class_id &lt; 13 ",
                        "</when>",
                        "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
                            "AND t1.class_type_id_new IN (${classTypeId}) ",
                        "</when>",
                        "<when test='type ==3'>",
                            "AND t2.teacher_id in(select admin_id from xmy_erp_db.role_admin where role_id = 1568160887369994242) ",
                        "</when>",
                        "<when test='trackId!=null and trackId!=&apos;&apos; and type ==1'>",
                        "AND t2.teacher_id in(select sourse_id from xmy_erp_db.track_detail where deleted = 0 and track_id =#{trackId}) ",
                            "</when>",
                        "<when test='trackId!=null and trackId!=&apos;&apos; and type ==4'>",
                            "AND t1.school_id in(select sourse_id from xmy_erp_db.track_detail where deleted = 0 and track_id =#{trackId}) ",
                        "</when>",
                        "<when test='name!=null and name!=&apos;&apos; '>",
                            "AND sff.`name` LIKE '%${name}%' ",
                        "</when>",
                        "GROUP BY",
                        "student_id ",
                        ") AS t01",
                        "INNER JOIN ( SELECT * FROM edu_task WHERE deleted = 0 and task_category_id = ${taskCategoryId} and subjects_id IN (${subjectsId}) and task_course_num BETWEEN ${lessonNumEnd} and ${lessonNumEnd} ) AS t02 ON t01.year_part = t02.year_part ",
                        "AND t01.quarter_num = t02.quarter_num ",
                        "AND t01.subjects_id = t02.subjects_id ",
                        "AND t01.class_type_id = t02.class_type_id",
                        "AND t01.year_class_id = t02.year_class_id",
                        "INNER JOIN (",
                            "SELECT",
                            "student_id,",
                            "add_date,",
                            "lesson_num_finish,",
                            "year_class_id,",
                            "course_version_id,",
                            "class_type_id,",
                            "year_part,",
                            "quarter_num,",
                            "IFNULL( lesson_num, 0 ) AS lesson_num,",
                            "right_num,",
                            "is_last,",
                            "is_first,",
                            "amend_num, ",
                            "pass_rade,",
                            "brush_count,",
                            "lowest_shutnum",
                            "FROM",
                            "cha_plan ",
                            "WHERE",
                            "year_part = ${yearPart} ",
                            "AND quarter_num = ${quarterNum} ",
                            "AND task_category_id = ${taskCategoryId} ",
                            "and deleted = 0",
                        ") AS t03 ON t01.year_part = t03.year_part ",
                        "AND t01.quarter_num = t03.quarter_num ",
                        "AND t01.student_id = t03.student_id ",
                        "AND t02.year_class_id = t03.year_class_id",
                        "AND t02.course_version_id = t03.course_version_id",
                        "AND t02.class_type_id = t03.class_type_id ",
                        "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
                            "and t01.subjects_id IN (${subjectsId})",
                        "</when>",
                        "AND t02.task_course_num = t03.lesson_num",
                        "and t03.is_first = 1",
                    ") AS diff1 ",
                    "INNER JOIN ( ",
                        "SELECT ",
                        "t01.school_id,",
                        "t01.year_part,",
                        "t01.quarter_num,",
                        "t02.course_version_id,",
                        "t01.grade_id,",
                        "t01.grade_name,",
                        "t01.teacher_id,",
                        "t01.teacher_name,",
                        "t01.class_type_id,",
                        "t01.year_class_id,",
                        "t01.student_id,",
                        "t02.task_course_num AS lesson_num,",
                        "t03.is_first,",
                        "t03.is_last,",
                        "IFNULL( t03.brush_count, 0 ) AS brush_count,",
                        "(CASE WHEN t03.right_num IS NOT NULL AND t03.pass_rade &gt; 0 AND ( t03.right_num + t03.amend_num ) &gt;= t03.lowest_shutnum AND ( t03.right_num / t03.lowest_shutnum )* 100 &gt;= t03.pass_rade THEN t03.lowest_shutnum ELSE t02.lowest_shutnum END ) AS lowest_shutnum,",
                        "IFNULL( t03.right_num, 0 ) AS right_num, ",
                        "IFNULL( t03.amend_num, 0 ) AS amend_num ",
                        "FROM ( ",
                            "SELECT",
                            "t1.*,",
                            "t1.class_type_id_new as class_type_id,",
                            "t2.teacher_id,",
                            "t2.`name` AS grade_name,",
                            "sff.`name` AS teacher_name",
                            "FROM",
                            "xmy_erp_db.student_grade AS t1",
                            "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id ",
                            "INNER JOIN xmy_erp_db.staff AS sff ON sff.id = t2.teacher_id",
                            "INNER JOIN per_student_account AS t3 ON t1.student_id = t3.student_id",
                            "LEFT JOIN xmy_erp_db.rade_exclude_student AS t4 ON t4.classify_id = 0 AND t4.deleted = 0 AND t4.type = 2 AND t1.student_id = t4.student_id AND t1.year_part = t4.year_part AND t1.quarter_num = t4.quarter_num AND ( FIND_IN_SET( t1.subjects_id, t4.subjects_ids ) OR t4.subjects_ids IS NULL ) AND ( FIND_IN_SET( t1.school_id, t4.school_ids ) OR t4.school_ids IS NULL ) ",
                            "WHERE",
                            "t1.year_part = ${yearPart} ",
                            "AND t1.quarter_num = ${quarterNum} ",
                            "AND t1.lesson_type = 1 ",
                            "AND t1.deleted = 0 ",
                            "AND t1.subjects_id IN (${subjectsId}) ",
                            "AND t1.is_last = 1 ",
                            "<when test='include!=null and include!=&apos;&apos;'>",
                                "<when test='include == 0'>",
                                    "and t4.id is null ",
                                "</when>",
                                "<when test='include == 1'>",
                                    "and t4.id is not null ",
                                "</when>",
                            "</when>",
                            "<when test='isBeforQuarter == 0 and readingType == 1'>",
                            "AND t1.reading_status IN (1,5) ",
                                "</when>",
                            "<when test='isBeforQuarter == 1 and readingType == 1'>",
                            "AND t1.reading_status IN (1,5)",
                                "</when>",
                            "<when test='readingType == 2'>",
                                "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and use_course_count &gt; 0)) ",
                            "</when>",
                            "AND t1.STATUS &lt;&gt; 3 ",
                            "AND t1.deleted = 0 ",

                            "<when test='schoolIdStr!=null and schoolIdStr!=&apos;&apos; and (type == 2 || type == 4)'>",
                                "AND t1.school_id in(${schoolIdStr}) ",
                            "</when>",
                            "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
                                "AND t2.teacher_id in(${teacherId}) ",
                            "</when>",
                            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
                                "AND t2.year_class_id in(${yearClassIdStr}) ",
                            "</when>",
                            "<when test='yearClassIdStr==null or yearClassIdStr==&apos;&apos; '>",
                                "AND t2.year_class_id &lt; 13 ",
                            "</when>",
                            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
                                "AND t1.class_type_id_new IN (${classTypeId}) ",
                            "</when>",
                            "<when test='type ==3'>",
                                "AND t2.teacher_id in(select admin_id from xmy_erp_db.role_admin where role_id = 1568160887369994242) ",
                            "</when>",
                            "<when test='trackId!=null and trackId!=&apos;&apos; and type ==1'>",
                                "AND t2.teacher_id in(select sourse_id from xmy_erp_db.track_detail where deleted = 0 and track_id =#{trackId}) ",
                            "</when>",
                            "<when test='trackId!=null and trackId!=&apos;&apos; and type ==4'>",
                                "AND t1.school_id in(select sourse_id from xmy_erp_db.track_detail where deleted = 0 and track_id =#{trackId}) ",
                            "</when>",
                            "<when test='name!=null and name!=&apos;&apos; '>",
                                "AND sff.`name` LIKE '%${name}%' ",
                            "</when>",
                            "GROUP BY",
                            "student_id ",
                            ") AS t01",
                            "INNER JOIN ( SELECT * FROM edu_task WHERE deleted = 0 and task_category_id = ${taskCategoryId} and subjects_id IN (${subjectsId}) and task_course_num BETWEEN ${lessonNumStart} and ${lessonNumStart} ) AS t02 ON t01.year_part = t02.year_part ",
                            "AND t01.quarter_num = t02.quarter_num ",
                            "AND t01.subjects_id = t02.subjects_id ",
                            "AND t01.class_type_id = t02.class_type_id",
                            "AND t01.year_class_id = t02.year_class_id",
                            "INNER JOIN (",
                            "SELECT",
                            "student_id,",
                            "add_date,",
                            "lesson_num_finish,",
                            "year_class_id,",
                            "course_version_id,",
                            "class_type_id,",
                            "year_part,",
                            "quarter_num,",
                            "IFNULL( lesson_num, 0 ) AS lesson_num,",
                            "right_num,",
                            "is_last,",
                            "is_first,",
                            "amend_num, ",
                            "pass_rade,",
                            "brush_count,",
                            "lowest_shutnum",
                            "FROM",
                            "cha_plan ",
                            "WHERE",
                            "year_part = ${yearPart} ",
                            "AND quarter_num = ${quarterNum} ",
                            "AND task_category_id = ${taskCategoryId} ",
                            "and deleted = 0",
                            ") AS t03 ON t01.year_part = t03.year_part ",
                            "AND t01.quarter_num = t03.quarter_num ",
                            "AND t01.student_id = t03.student_id ",
                            "AND t02.year_class_id = t03.year_class_id",
                            "AND t02.course_version_id = t03.course_version_id",
                            "AND t02.class_type_id = t03.class_type_id ",
                            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
                                "and t01.subjects_id IN (${subjectsId})",
                            "</when>",
                            "AND t02.task_course_num = t03.lesson_num",
                            "and t03.is_first = 1",
                        ") AS diff2 ON diff1.student_id = diff2.student_id ",
                "<when test='type == 6'>",
                    ") AS diff01 ON t01.school_id = diff01.school_id ",
                "</when>",
                "<when test='type != 6'>",
                    ") AS diff01 ",
                "</when>",
            "WHERE 1=1 ",
            "<when test='schoolIdStr!=null and schoolIdStr!=&apos;&apos; and (type == 2)'>",
            "   and school_id in(${schoolIdStr})",
            "</when>",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
                "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
                "and class_type_id IN (${classTypeId})",
            "</when>",
            "<when test='type ==3'>",
                "and teacher_id in(select admin_id from xmy_erp_db.role_admin where role_id = 1568160887369994242) ",
            "</when>",
            "<when test='trackId!=null and trackId!=&apos;&apos; and type ==1'>",
                "and teacher_id in(select sourse_id from xmy_erp_db.track_detail where deleted = 0 and track_id = #{trackId}) ",
            "</when>",
            "<when test='trackId!=null and trackId!=&apos;&apos; and type ==4'>",
                "and school_id in(select sourse_id from xmy_erp_db.track_detail where deleted = 0 and track_id = #{trackId}) ",
            "</when>",
            "GROUP BY ",
            "<when test='type == 1 or type == 3'>",
                "teacher_id",
            "</when>",
            "<when test='type == 2'>",
                "school_id,teacher_id",
            "</when>",
            "<when test='type == 4 or type == 6'>",
                "school_id",
            "</when>",
            "</script>"})
    public List<ChaPlan> getHonorList(@Param("yearPart") String yearPart,
                                      @Param("quarterNum") String quarterNum,
                                      @Param("schoolIdStr") String schoolIdStr,
                                      @Param("yearClassIdStr") String yearClassIdStr,
                                      @Param("type") String type,
                                      @Param("lessonNumStart") String lessonNumStart,
                                      @Param("lessonNumEnd") String lessonNumEnd,
                                      @Param("classTypeId") String classTypeId,
                                      @Param("readingType") String readingType,
                                      @Param("subjectsId") String subjectsId,
                                      @Param("isBeforQuarter") String isBeforQuarter,
                                      @Param("trackId") String trackId,
                                      @Param("teacherId") String teacherId,
                                      @Param("name") String name,
                                      @Param("include") String include,
                                      @Param("taskCategoryId") Integer taskCategoryId,
                                      @Param("startDate") String startDate,
                                      @Param("endDate") String endDate
    );


    /**
     * 荣誉榜单详情
     */
    @Select({"<script>",
            "SELECT",
            "diff01.*",
            "FROM",
            "(",
            "SELECT",
            "diff1.*, ",
            "diff2.lowest_shutnum AS lowest_shutnum2,",
            "diff2.right_num AS right_num2,",
            "diff2.amend_num AS amend_num2,",
            "ROUND((( diff1.right_num / diff1.lowest_shutnum )* 100 ), 2 ) AS right_rade, ",
            "ROUND((( diff2.right_num / diff2.lowest_shutnum )* 100 ), 2 ) AS right_rade2 ",
            "FROM",
            "(",
            "SELECT ",
            "t01.school_id,",
            "t01.year_part,",
            "t01.quarter_num,",
            "t02.course_version_id,",
            "t01.grade_id,",
            "t01.grade_name,",
            "t01.teacher_id,",
            "t01.teacher_name,",
            "t01.class_type_id,",
            "t01.year_class_id,",
            "t01.student_id,",
            "t02.task_course_num AS lesson_num,",
            "t03.is_first,",
            "t03.is_last,",
            "t03.add_date,",
            "IFNULL( t03.brush_count, 0 ) AS brush_count,",
            "(CASE WHEN t03.right_num IS NOT NULL AND t03.pass_rade &gt; 0 AND ( t03.right_num + t03.amend_num ) &gt;= t03.lowest_shutnum AND ( t03.right_num / t03.lowest_shutnum )* 100 &gt;= t03.pass_rade THEN t03.lowest_shutnum ELSE t02.lowest_shutnum END ) AS lowest_shutnum,",
            "IFNULL( t03.right_num, 0 ) AS right_num, ",
            "IFNULL( t03.amend_num, 0 ) AS amend_num ",
            "FROM ( ",
            "SELECT",
            "t1.*,",
            "t1.class_type_id_new as class_type_id,",
            "t2.teacher_id,",
            "t2.`name` AS grade_name,",
            "sff.`name` AS teacher_name",
            "FROM",
            "xmy_erp_db.student_grade AS t1",
            "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id ",
            "INNER JOIN xmy_erp_db.staff AS sff ON sff.id = t2.teacher_id",
            "INNER JOIN per_student_account AS t3 ON t1.student_id = t3.student_id",
            "LEFT JOIN xmy_erp_db.rade_exclude_student AS t4 ON t4.classify_id = 0 AND t4.deleted = 0 AND t4.type = 2 AND t1.student_id = t4.student_id AND t1.year_part = t4.year_part AND t1.quarter_num = t4.quarter_num AND ( FIND_IN_SET( t1.subjects_id, t4.subjects_ids ) OR t4.subjects_ids IS NULL ) AND ( FIND_IN_SET( t1.school_id, t4.school_ids ) OR t4.school_ids IS NULL ) ",
            "WHERE",
            "t1.year_part = ${yearPart} ",
            "AND t1.quarter_num = ${quarterNum} ",
            "AND t1.lesson_type = 1 ",
            "AND t1.deleted = 0 ",
            "AND t1.subjects_id IN (${subjectsId}) ",
            "AND t1.is_last = 1 ",
            "<when test='include!=null and include!=&apos;&apos;'>",
            "<when test='include == 0'>",
            "and t4.id is null ",
            "</when>",
            "<when test='include == 1'>",
            "and t4.id is not null ",
            "</when>",
            "</when>",
            "<when test='isBeforQuarter == 0 and readingType == 1'>",
            "AND t1.reading_status IN (1,5) ",
            "</when>",
            "<when test='isBeforQuarter == 1 and readingType == 1'>",
            "AND t1.reading_status IN (1,5)",
            "</when>",
            "<when test='readingType == 2'>",
            "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and use_course_count &gt; 0)) ",
            "</when>",
            "AND t1.STATUS &lt;&gt; 3 ",
            "AND t1.deleted = 0 ",
            "<when test='gradeId!=null and gradeId!=&apos;&apos;'>",
            "and t1.grade_id = ${gradeId}",
            "</when>",
            "<when test='schoolIdStr!=null and schoolIdStr!=&apos;&apos; and (type == 2 || type == 4)'>",
            "AND t1.school_id in(${schoolIdStr}) ",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
            "AND t2.teacher_id in(${teacherId}) ",
            "</when>",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "AND t2.year_class_id in(${yearClassIdStr}) ",
            "</when>",
            "<when test='yearClassIdStr==null or yearClassIdStr==&apos;&apos; '>",
            "AND t2.year_class_id &lt; 13 ",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "AND t1.class_type_id_new IN (${classTypeId}) ",
            "</when>",
            "<when test='type ==3'>",
            "AND t2.teacher_id in(select admin_id from xmy_erp_db.role_admin where role_id = 1568160887369994242) ",
            "</when>",
            "<when test='trackId!=null and trackId!=&apos;&apos; and type ==1'>",
            "AND t2.teacher_id in(select sourse_id from xmy_erp_db.track_detail where deleted = 0 and track_id =#{trackId}) ",
            "</when>",
            "<when test='trackId!=null and trackId!=&apos;&apos; and type ==4'>",
            "AND t1.school_id in(select sourse_id from xmy_erp_db.track_detail where deleted = 0 and track_id =#{trackId}) ",
            "</when>",
            "<when test='name!=null and name!=&apos;&apos; '>",
            "AND sff.`name` LIKE '%${name}%' ",
            "</when>",
            "GROUP BY",
            "student_id ",
            ") AS t01",
            "INNER JOIN ( SELECT * FROM edu_task WHERE deleted = 0 and task_category_id = ${taskCategoryId} and subjects_id IN (${subjectsId}) and task_course_num BETWEEN ${lessonNumEnd} and ${lessonNumEnd} ) AS t02 ON t01.year_part = t02.year_part ",
            "AND t01.quarter_num = t02.quarter_num ",
            "AND t01.subjects_id = t02.subjects_id ",
            "AND t01.class_type_id = t02.class_type_id",
            "AND t01.year_class_id = t02.year_class_id",
            "INNER JOIN ( ",
            "SELECT",
            "student_id,",
            "add_date,",
            "lesson_num_finish,",
            "year_class_id,",
            "course_version_id,",
            "class_type_id,",
            "year_part,",
            "quarter_num,",
            "IFNULL( lesson_num, 0 ) AS lesson_num,",
            "right_num,",
            "is_last,",
            "is_first,",
            "amend_num, ",
            "pass_rade,",
            "brush_count,",
            "lowest_shutnum",
            "FROM",
            "cha_plan ",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND quarter_num = ${quarterNum} ",
            "AND task_category_id = ${taskCategoryId} ",
            "and deleted = 0",
            ") AS t03 ON t01.year_part = t03.year_part ",
            "AND t01.quarter_num = t03.quarter_num ",
            "AND t01.student_id = t03.student_id ",
            "AND t02.year_class_id = t03.year_class_id",
            "AND t02.course_version_id = t03.course_version_id",
            "AND t02.class_type_id = t03.class_type_id ",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and t01.subjects_id IN (${subjectsId})",
            "</when>",
            "AND t02.task_course_num = t03.lesson_num",
            "AND t03.is_first = 1",
            ") AS diff1 ",
            "INNER JOIN ( ",
            "SELECT ",
            "t01.school_id,",
            "t01.year_part,",
            "t01.quarter_num,",
            "t02.course_version_id,",
            "t01.grade_id,",
            "t01.grade_name,",
            "t01.teacher_id,",
            "t01.teacher_name,",
            "t01.class_type_id,",
            "t01.year_class_id,",
            "t01.student_id,",
            "t02.task_course_num AS lesson_num,",
            "t03.is_first,",
            "t03.is_last,",
            "IFNULL( t03.brush_count, 0 ) AS brush_count,",
            "(CASE WHEN t03.right_num IS NOT NULL AND t03.pass_rade &gt; 0 AND ( t03.right_num + t03.amend_num ) &gt;= t03.lowest_shutnum AND ( t03.right_num / t03.lowest_shutnum )* 100 &gt;= t03.pass_rade THEN t03.lowest_shutnum ELSE t02.lowest_shutnum END ) AS lowest_shutnum,",
            "IFNULL( t03.right_num, 0 ) AS right_num, ",
            "IFNULL( t03.amend_num, 0 ) AS amend_num ",
            "FROM ( ",
            "SELECT",
            "t1.*,",
            "t1.class_type_id_new as class_type_id,",
            "t2.teacher_id,",
            "t2.`name` AS grade_name,",
            "sff.`name` AS teacher_name",
            "FROM",
            "xmy_erp_db.student_grade AS t1",
            "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id ",
            "INNER JOIN xmy_erp_db.staff AS sff ON sff.id = t2.teacher_id",
            "INNER JOIN per_student_account AS t3 ON t1.student_id = t3.student_id",
            "LEFT JOIN xmy_erp_db.rade_exclude_student AS t4 ON t4.classify_id = 0 AND t4.deleted = 0 AND t4.type = 2 AND t1.student_id = t4.student_id AND t1.year_part = t4.year_part AND t1.quarter_num = t4.quarter_num AND ( FIND_IN_SET( t1.subjects_id, t4.subjects_ids ) OR t4.subjects_ids IS NULL ) AND ( FIND_IN_SET( t1.school_id, t4.school_ids ) OR t4.school_ids IS NULL ) ",
            "WHERE",
            "t1.year_part = ${yearPart} ",
            "AND t1.quarter_num = ${quarterNum} ",
            "AND t1.lesson_type = 1 ",
            "AND t1.deleted = 0 ",
            "AND t1.subjects_id IN (${subjectsId}) ",
            "AND t1.is_last = 1 ",
            "<when test='include!=null and include!=&apos;&apos;'>",
            "<when test='include == 0'>",
            "and t4.id is null ",
            "</when>",
            "<when test='include == 1'>",
            "and t4.id is not null ",
            "</when>",
            "</when>",
            "<when test='isBeforQuarter == 0 and readingType == 1'>",
            "AND t1.reading_status IN (1,5) ",
            "</when>",
            "<when test='isBeforQuarter == 1 and readingType == 1'>",
            "AND t1.reading_status IN (1,5)",
            "</when>",
            "<when test='readingType == 2'>",
            "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and use_course_count &gt; 0)) ",
            "</when>",
            "AND t1.STATUS &lt;&gt; 3 ",
            "AND t1.deleted = 0 ",
            "<when test='gradeId!=null and gradeId!=&apos;&apos;'>",
            "and t1.grade_id = ${gradeId}",
            "</when>",
            "<when test='schoolIdStr!=null and schoolIdStr!=&apos;&apos; and (type == 2 || type == 4)'>",
            "AND t1.school_id in(${schoolIdStr}) ",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
            "AND t2.teacher_id in(${teacherId}) ",
            "</when>",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "AND t2.year_class_id in(${yearClassIdStr}) ",
            "</when>",
            "<when test='yearClassIdStr==null or yearClassIdStr==&apos;&apos; '>",
            "AND t2.year_class_id &lt; 13 ",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "AND t1.class_type_id_new IN (${classTypeId}) ",
            "</when>",
            "<when test='type ==3'>",
            "AND t2.teacher_id in(select admin_id from xmy_erp_db.role_admin where role_id = 1568160887369994242) ",
            "</when>",
            "<when test='trackId!=null and trackId!=&apos;&apos; and type ==1'>",
            "AND t2.teacher_id in(select sourse_id from xmy_erp_db.track_detail where deleted = 0 and track_id =#{trackId}) ",
            "</when>",
            "<when test='trackId!=null and trackId!=&apos;&apos; and type ==4'>",
            "AND t1.school_id in(select sourse_id from xmy_erp_db.track_detail where deleted = 0 and track_id =#{trackId}) ",
            "</when>",
            "<when test='name!=null and name!=&apos;&apos; '>",
            "AND sff.`name` LIKE '%${name}%' ",
            "</when>",
            "GROUP BY",
            "student_id ",
            ") AS t01",
            "INNER JOIN ( SELECT * FROM edu_task WHERE deleted = 0 and task_category_id = ${taskCategoryId} and subjects_id IN (${subjectsId}) and task_course_num BETWEEN ${lessonNumStart} and ${lessonNumStart} ) AS t02 ON t01.year_part = t02.year_part ",
            "AND t01.quarter_num = t02.quarter_num ",
            "AND t01.subjects_id = t02.subjects_id ",
            "AND t01.class_type_id = t02.class_type_id",
            "AND t01.year_class_id = t02.year_class_id",
            "INNER JOIN ( ",
            "SELECT",
            "student_id,",
            "add_date,",
            "lesson_num_finish,",
            "year_class_id,",
            "course_version_id,",
            "class_type_id,",
            "year_part,",
            "quarter_num,",
            "IFNULL( lesson_num, 0 ) AS lesson_num,",
            "right_num,",
            "is_last,",
            "is_first,",
            "amend_num, ",
            "pass_rade,",
            "brush_count,",
            "lowest_shutnum",
            "FROM",
            "cha_plan ",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND quarter_num = ${quarterNum} ",
            "AND task_category_id = ${taskCategoryId} ",
            "and deleted = 0",
            ") AS t03 ON t01.year_part = t03.year_part ",
            "AND t01.quarter_num = t03.quarter_num ",
            "AND t01.student_id = t03.student_id ",
            "AND t02.year_class_id = t03.year_class_id",
            "AND t02.course_version_id = t03.course_version_id",
            "AND t02.class_type_id = t03.class_type_id ",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and t01.subjects_id IN (${subjectsId})",
            "</when>",
            "AND t02.task_course_num = t03.lesson_num",
            "and t03.is_first = 1",
            ") AS diff2 ON diff1.student_id = diff2.student_id ",
            ") AS diff01 ",
            "WHERE 1=1 ",
            "<when test='startDate!=null and startDate!=&apos;&apos; and endDate!=null and endDate!=&apos;&apos;'>",
                "and add_date BETWEEN '${startDate}' AND '${endDate}'",
            "</when>",
            "<when test='schoolIdStr!=null and schoolIdStr!=&apos;&apos;'>",
                "AND school_id in (${schoolIdStr}) ",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
                "AND teacher_id in(${teacherId}) ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 1'>",// 普通
                "AND right_rade &lt; right_rade2 ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 2'>",// 进步
                "AND right_rade &gt;= right_rade2 ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 3'>",// 优秀
                "AND right_rade &gt;= 90 ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 4'>",// 学霸
                "AND right_rade &gt;= 100 ",
            "</when>",
            "</script>"})
    public IPage<ChaPlan> getHonorDetails(IPage<?> page,
                                          @Param("yearPart") String yearPart,
                                          @Param("quarterNum") String quarterNum,
                                          @Param("schoolIdStr") String schoolIdStr,
                                          @Param("yearClassIdStr") String yearClassIdStr,
                                          @Param("type") String type,
                                          @Param("lessonNumStart") String lessonNumStart,
                                          @Param("lessonNumEnd") String lessonNumEnd,
                                          @Param("classTypeId") String classTypeId,
                                          @Param("readingType") String readingType,
                                          @Param("subjectsId") String subjectsId,
                                          @Param("isBeforQuarter") String isBeforQuarter,
                                          @Param("trackId") String trackId,
                                          @Param("teacherId") String teacherId,
                                          @Param("name") String name,
                                          @Param("include") String include,
                                          @Param("taskCategoryId") Integer taskCategoryId,
                                          @Param("passType") String passType,
                                          @Param("gradeId") String gradeId,
                                          @Param("startDate") String startDate,
                                          @Param("endDate") String endDate
    );

    /**
     * 荣誉榜单战队列表
     */
    @Select({"<script>",
            "SELECT",
            "diff01.school_id,",
            "diff01.teacher_id,",
            "diff01.teacher_name,",
            "diff01.year_part,",
            "diff01.quarter_num,",
            "t1.team_id,",
            "t1.team_pid,",
            "t1.team_name,",
            "COUNT(student_id) AS showPassNum,",

            "SUM( CASE WHEN right_rade &lt; right_rade2 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS ordinary_count, ",

            "SUM( CASE WHEN right_rade &gt;= right_rade2 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS progress_count, ",

            "SUM( CASE WHEN right_rade &gt;= 90 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS excellent_count,",

            "SUM( CASE WHEN right_rade &gt;= 100 ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS apex_count, ",

            "SUM( CASE WHEN right_rade &lt; right_rade2 AND add_date BETWEEN '${startDate}' AND '${endDate}' ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS ordinary_num, ",

            "SUM( CASE WHEN right_rade &gt;= right_rade2 AND add_date BETWEEN '${startDate}' AND '${endDate}' ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS progress_num, ",

            "SUM( CASE WHEN right_rade &gt;= 90 AND add_date BETWEEN '${startDate}' AND '${endDate}' ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS excellent_num,",

            "SUM( CASE WHEN right_rade &gt;= 100 AND add_date BETWEEN '${startDate}' AND '${endDate}' ",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and year_class_id in(${yearClassIdStr})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and class_type_id IN (${classTypeId})",
            "</when>",
            "THEN 1 ELSE 0 END ) AS apex_num ",

            "FROM",
            "(",
            "SELECT ",
            "td.*, ",
            "td.sourse_id AS teacher_id,",
            "tm.team_name,",
            "tm.id AS team_id,",
            "tm.pid AS team_pid ",
            "FROM",
            "xmy_erp_db.track_market AS tm",
            "LEFT JOIN xmy_erp_db.track_detail AS td ON tm.id = td.track_id AND tm.deleted = td.deleted ",
            "WHERE ",
            "tm.classify = ${classify} ",
            "AND tm.track_type = ${trackType} ",
            "AND tm.`status` = 1 ",
            "AND tm.deleted = 0 ",
            "AND tm.year_part = ${yearPart} ",
            "AND tm.quarter_num = ${quarterNum} ",
            "<when test='teamId!=null and teamId!=&apos;&apos; '>",
            "AND tm.id in(${teamId})",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
            "AND td.sourse_id = ${teacherId}",
            "</when>",
            "GROUP BY tm.id,td.sourse_id ",
            ") AS t1",

            "LEFT JOIN (",
            "SELECT ",
            "diff1.*,",
            "diff2.lowest_shutnum AS lowest_shutnum2, ",
            "diff2.right_num AS right_num2,",
            "diff2.amend_num AS amend_num2,",
            "ROUND((( diff1.right_num / diff1.lowest_shutnum )* 100 ), 2 ) AS right_rade, ",
            "ROUND((( diff2.right_num / diff2.lowest_shutnum )* 100 ), 2 ) AS right_rade2 ",
            "FROM ( ",
            "SELECT ",
            "t01.school_id,",
            "t01.year_part,",
            "t01.quarter_num,",
            "t02.course_version_id,",
            "t01.grade_id,",
            "t01.grade_name,",
            "t01.teacher_id,",
            "t01.teacher_name,",
            "t01.class_type_id,",
            "t01.year_class_id,",
            "t01.student_id,",
            "t02.task_course_num AS lesson_num,",
            "t03.is_first,",
            "t03.is_last,",
            "t03.add_date,",
            "IFNULL( t03.brush_count, 0 ) AS brush_count,",
            "(CASE WHEN t03.right_num IS NOT NULL AND t03.pass_rade &gt; 0 AND ( t03.right_num + t03.amend_num ) &gt;= t03.lowest_shutnum AND ( t03.right_num / t03.lowest_shutnum )* 100 &gt;= t03.pass_rade THEN t03.lowest_shutnum ELSE t02.lowest_shutnum END ) AS lowest_shutnum,",
            "IFNULL( t03.right_num, 0 ) AS right_num, ",
            "IFNULL( t03.amend_num, 0 ) AS amend_num ",
            "FROM ( ",
            "SELECT",
            "t1.*,",
            "t1.class_type_id_new as class_type_id,",
            "t2.teacher_id,",
            "t2.`name` AS grade_name,",
            "sff.`name` AS teacher_name",
            "FROM",
            "xmy_erp_db.student_grade AS t1",
            "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id ",
            "INNER JOIN xmy_erp_db.staff AS sff ON sff.id = t2.teacher_id",
            "INNER JOIN per_student_account AS t3 ON t1.student_id = t3.student_id",
            "LEFT JOIN xmy_erp_db.rade_exclude_student AS t4 ON t4.classify_id = 0 AND t4.deleted = 0 AND t4.type = 2 AND t1.student_id = t4.student_id AND t1.year_part = t4.year_part AND t1.quarter_num = t4.quarter_num AND ( FIND_IN_SET( t1.subjects_id, t4.subjects_ids ) OR t4.subjects_ids IS NULL ) AND ( FIND_IN_SET( t1.school_id, t4.school_ids ) OR t4.school_ids IS NULL ) ",
            "WHERE",
            "t1.year_part = ${yearPart} ",
            "AND t1.quarter_num = ${quarterNum} ",
            "AND t1.lesson_type = 1 ",
            "AND t1.deleted = 0 ",
            "AND t1.subjects_id IN (${subjectsId}) ",
            "AND t1.is_last = 1 ",
            "<when test='include!=null and include!=&apos;&apos;'>",
            "<when test='include == 0'>",
            "and t4.id is null ",
            "</when>",
            "<when test='include == 1'>",
            "and t4.id is not null ",
            "</when>",
            "</when>",
            "<when test='isBeforQuarter == 0 and readingType == 1'>",
            "AND t1.reading_status IN (1,5) ",
            "</when>",
            "<when test='isBeforQuarter == 1 and readingType == 1'>",
            "AND t1.reading_status IN (1,5)",
            "</when>",
            "<when test='readingType == 2'>",
            "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and use_course_count &gt; 0)) ",
            "</when>",
            "AND t1.STATUS &lt;&gt; 3 ",
            "AND t1.deleted = 0 ",
            "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
            "AND t2.teacher_id in(${teacherId}) ",
            "</when>",
            "<when test='yearClassIdStr==null or yearClassIdStr==&apos;&apos; '>",
            "AND t2.year_class_id &lt; 13 ",
            "</when>",
            "<when test='name!=null and name!=&apos;&apos; '>",
            "AND sff.`name` LIKE '%${name}%' ",
            "</when>",
            "GROUP BY",
            "student_id ",
            ") AS t01",
            "INNER JOIN ( SELECT * FROM edu_task WHERE deleted = 0 and task_category_id = ${taskCategoryId} and subjects_id IN (${subjectsId}) and task_course_num BETWEEN ${lessonNumEnd} and ${lessonNumEnd} ) AS t02 ON t01.year_part = t02.year_part ",
            "AND t01.quarter_num = t02.quarter_num ",
            "AND t01.subjects_id = t02.subjects_id ",
            "AND t01.class_type_id = t02.class_type_id",
            "AND t01.year_class_id = t02.year_class_id",
            "INNER JOIN (",
            "SELECT",
            "student_id,",
            "add_date,",
            "lesson_num_finish,",
            "year_class_id,",
            "course_version_id,",
            "class_type_id,",
            "year_part,",
            "quarter_num,",
            "IFNULL( lesson_num, 0 ) AS lesson_num,",
            "right_num,",
            "is_last,",
            "is_first,",
            "amend_num, ",
            "pass_rade,",
            "brush_count,",
            "lowest_shutnum",
            "FROM",
            "cha_plan ",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND quarter_num = ${quarterNum} ",
            "AND task_category_id = ${taskCategoryId} ",
            "and deleted = 0",
            ") AS t03 ON t01.year_part = t03.year_part ",
            "AND t01.quarter_num = t03.quarter_num ",
            "AND t01.student_id = t03.student_id ",
            "AND t02.year_class_id = t03.year_class_id",
            "AND t02.course_version_id = t03.course_version_id",
            "AND t02.class_type_id = t03.class_type_id ",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and t01.subjects_id IN (${subjectsId})",
            "</when>",
            "AND t02.task_course_num = t03.lesson_num",
            "and t03.is_first = 1",
            ") AS diff1 ",
            "INNER JOIN ( ",
            "SELECT ",
            "t01.school_id,",
            "t01.year_part,",
            "t01.quarter_num,",
            "t02.course_version_id,",
            "t01.grade_id,",
            "t01.grade_name,",
            "t01.teacher_id,",
            "t01.teacher_name,",
            "t01.class_type_id,",
            "t01.year_class_id,",
            "t01.student_id,",
            "t02.task_course_num AS lesson_num,",
            "t03.is_first,",
            "t03.is_last,",
            "IFNULL( t03.brush_count, 0 ) AS brush_count,",
            "(CASE WHEN t03.right_num IS NOT NULL AND t03.pass_rade &gt; 0 AND ( t03.right_num + t03.amend_num ) &gt;= t03.lowest_shutnum AND ( t03.right_num / t03.lowest_shutnum )* 100 &gt;= t03.pass_rade THEN t03.lowest_shutnum ELSE t02.lowest_shutnum END ) AS lowest_shutnum,",
            "IFNULL( t03.right_num, 0 ) AS right_num, ",
            "IFNULL( t03.amend_num, 0 ) AS amend_num ",
            "FROM ( ",
            "SELECT",
            "t1.*,",
            "t1.class_type_id_new as class_type_id,",
            "t2.teacher_id,",
            "t2.`name` AS grade_name,",
            "sff.`name` AS teacher_name",
            "FROM",
            "xmy_erp_db.student_grade AS t1",
            "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id ",
            "INNER JOIN xmy_erp_db.staff AS sff ON sff.id = t2.teacher_id",
            "INNER JOIN per_student_account AS t3 ON t1.student_id = t3.student_id",
            "LEFT JOIN xmy_erp_db.rade_exclude_student AS t4 ON t4.classify_id = 0 AND t4.deleted = 0 AND t4.type = 2 AND t1.student_id = t4.student_id AND t1.year_part = t4.year_part AND t1.quarter_num = t4.quarter_num AND ( FIND_IN_SET( t1.subjects_id, t4.subjects_ids ) OR t4.subjects_ids IS NULL ) AND ( FIND_IN_SET( t1.school_id, t4.school_ids ) OR t4.school_ids IS NULL ) ",
            "WHERE",
            "t1.year_part = ${yearPart} ",
            "AND t1.quarter_num = ${quarterNum} ",
            "AND t1.lesson_type = 1 ",
            "AND t1.deleted = 0 ",
            "AND t1.subjects_id IN (${subjectsId}) ",
            "AND t1.is_last = 1 ",
            "<when test='include!=null and include!=&apos;&apos;'>",
            "<when test='include == 0'>",
            "and t4.id is null ",
            "</when>",
            "<when test='include == 1'>",
            "and t4.id is not null ",
            "</when>",
            "</when>",
            "<when test='isBeforQuarter == 0 and readingType == 1'>",
            "AND t1.reading_status IN (1,5) ",
            "</when>",
            "<when test='isBeforQuarter == 1 and readingType == 1'>",
            "AND t1.reading_status IN (1,5)",
            "</when>",
            "<when test='readingType == 2'>",
            "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and use_course_count &gt; 0)) ",
            "</when>",
            "AND t1.STATUS &lt;&gt; 3 ",
            "AND t1.deleted = 0 ",
            "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
            "AND t2.teacher_id in(${teacherId}) ",
            "</when>",
            "<when test='yearClassIdStr==null or yearClassIdStr==&apos;&apos; '>",
            "AND t2.year_class_id &lt; 13 ",
            "</when>",
            "<when test='name!=null and name!=&apos;&apos; '>",
            "AND sff.`name` LIKE '%${name}%' ",
            "</when>",
            "GROUP BY",
            "student_id ",
            ") AS t01",
            "INNER JOIN ( SELECT * FROM edu_task WHERE deleted = 0 and task_category_id = ${taskCategoryId} and subjects_id IN (${subjectsId}) and task_course_num BETWEEN ${lessonNumStart} and ${lessonNumStart} ) AS t02 ON t01.year_part = t02.year_part ",
            "AND t01.quarter_num = t02.quarter_num ",
            "AND t01.subjects_id = t02.subjects_id ",
            "AND t01.class_type_id = t02.class_type_id",
            "AND t01.year_class_id = t02.year_class_id",
            "INNER JOIN (",
            "SELECT",
            "student_id,",
            "add_date,",
            "lesson_num_finish,",
            "year_class_id,",
            "course_version_id,",
            "class_type_id,",
            "year_part,",
            "quarter_num,",
            "IFNULL( lesson_num, 0 ) AS lesson_num,",
            "right_num,",
            "is_last,",
            "is_first,",
            "amend_num, ",
            "pass_rade,",
            "brush_count,",
            "lowest_shutnum",
            "FROM",
            "cha_plan ",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND quarter_num = ${quarterNum} ",
            "AND task_category_id = ${taskCategoryId} ",
            "and deleted = 0",
            ") AS t03 ON t01.year_part = t03.year_part ",
            "AND t01.quarter_num = t03.quarter_num ",
            "AND t01.student_id = t03.student_id ",
            "AND t02.year_class_id = t03.year_class_id",
            "AND t02.course_version_id = t03.course_version_id",
            "AND t02.class_type_id = t03.class_type_id ",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and t01.subjects_id IN (${subjectsId})",
            "</when>",
            "AND t02.task_course_num = t03.lesson_num",
            "and t03.is_first = 1",
            ") AS diff2 ON diff1.student_id = diff2.student_id ",
            ") AS diff01 ON diff01.teacher_id = t1.teacher_id ",
            "AND ( find_in_set( diff01.year_class_id, t1.year_class_id_str ) OR t1.year_class_id_str = '' ) ",
            "AND ( find_in_set( diff01.school_id, t1.school_id_str ) OR t1.school_id_str = '' ) ",
            "GROUP BY team_id",
            "<when test='teamId!=null and teamId!=&apos;&apos; '>",
            ",diff01.teacher_id",
            "HAVING diff01.teacher_id IS NOT NULL",
            "</when>",
            "</script>"})
    public List<ChaPlan> getHonorTeamList(@Param("yearPart") String yearPart,
                                          @Param("quarterNum") String quarterNum,
                                          @Param("yearClassIdStr") String yearClassIdStr,
                                          @Param("lessonNumStart") String lessonNumStart,
                                          @Param("lessonNumEnd") String lessonNumEnd,
                                          @Param("classTypeId") String classTypeId,
                                          @Param("readingType") String readingType,
                                          @Param("subjectsId") String subjectsId,
                                          @Param("isBeforQuarter") String isBeforQuarter,
                                          @Param("teacherId") String teacherId,
                                          @Param("name") String name,
                                          @Param("include") String include,
                                          @Param("taskCategoryId") Integer taskCategoryId,
                                          @Param("classify") String classify,
                                          @Param("trackType") String trackType,
                                          @Param("teamId") String teamId,
                                          @Param("startDate") String startDate,
                                          @Param("endDate") String endDate
    );


    /**
     * 荣誉榜单战队详情
     */
    @Select({"<script>",
            "SELECT",
            "diff01.*,t1.team_id,t1.team_pid,t1.team_name ",
            "FROM",
            "(",
            "SELECT",
            "diff1.*, ",
            "diff2.lowest_shutnum AS lowest_shutnum2,",
            "diff2.right_num AS right_num2,",
            "diff2.amend_num AS amend_num2,",
            "ROUND((( diff1.right_num / diff1.lowest_shutnum )* 100 ), 2 ) AS right_rade, ",
            "ROUND((( diff2.right_num / diff2.lowest_shutnum )* 100 ), 2 ) AS right_rade2 ",
            "FROM",
            "(",
            "SELECT ",
            "td.*, ",
            "td.sourse_id AS teacher_id,",
            "tm.team_name,",
            "tm.id AS team_id,",
            "tm.pid AS team_pid ",
            "FROM",
            "xmy_erp_db.track_market AS tm",
            "LEFT JOIN xmy_erp_db.track_detail AS td ON tm.id = td.track_id AND tm.deleted = td.deleted ",
            "WHERE ",
            "tm.classify = ${classify} ",
            "AND tm.track_type = ${trackType} ",
            "AND tm.`status` = 1 ",
            "AND tm.deleted = 0 ",
            "AND tm.year_part = ${yearPart} ",
            "AND tm.quarter_num = ${quarterNum} ",
            "<when test='teamId!=null and teamId!=&apos;&apos; '>",
            "AND tm.id in(${teamId})",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
            "AND td.sourse_id = ${teacherId}",
            "</when>",
            "GROUP BY tm.id,td.sourse_id ",
            ") AS t1",

            "LEFT JOIN (",
            "SELECT ",
            "diff1.*,",
            "diff2.lowest_shutnum AS lowest_shutnum2, ",
            "diff2.right_num AS right_num2,",
            "diff2.amend_num AS amend_num2,",
            "ROUND((( diff1.right_num / diff1.lowest_shutnum )* 100 ), 2 ) AS right_rade, ",
            "ROUND((( diff2.right_num / diff2.lowest_shutnum )* 100 ), 2 ) AS right_rade2 ",
            "FROM ( ",
            "SELECT ",
            "t01.school_id,",
            "t01.year_part,",
            "t01.quarter_num,",
            "t02.course_version_id,",
            "t01.grade_id,",
            "t01.grade_name,",
            "t01.teacher_id,",
            "t01.teacher_name,",
            "t01.class_type_id,",
            "t01.year_class_id,",
            "t01.student_id,",
            "t02.task_course_num AS lesson_num,",
            "t03.is_first,",
            "t03.is_last,",
            "IFNULL( t03.brush_count, 0 ) AS brush_count,",
            "(CASE WHEN t03.right_num IS NOT NULL AND t03.pass_rade &gt; 0 AND ( t03.right_num + t03.amend_num ) &gt;= t03.lowest_shutnum AND ( t03.right_num / t03.lowest_shutnum )* 100 &gt;= t03.pass_rade THEN t03.lowest_shutnum ELSE t02.lowest_shutnum END ) AS lowest_shutnum,",
            "IFNULL( t03.right_num, 0 ) AS right_num, ",
            "IFNULL( t03.amend_num, 0 ) AS amend_num ",
            "FROM ( ",
            "SELECT",
            "t1.*,",
            "t1.class_type_id_new as class_type_id,",
            "t2.teacher_id,",
            "t2.`name` AS grade_name,",
            "sff.`name` AS teacher_name",
            "FROM",
            "xmy_erp_db.student_grade AS t1",
            "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id ",
            "INNER JOIN xmy_erp_db.staff AS sff ON sff.id = t2.teacher_id",
            "INNER JOIN per_student_account AS t3 ON t1.student_id = t3.student_id",
            "LEFT JOIN xmy_erp_db.rade_exclude_student AS t4 ON t4.classify_id = 0 AND t4.deleted = 0 AND t4.type = 2 AND t1.student_id = t4.student_id AND t1.year_part = t4.year_part AND t1.quarter_num = t4.quarter_num AND ( FIND_IN_SET( t1.subjects_id, t4.subjects_ids ) OR t4.subjects_ids IS NULL ) AND ( FIND_IN_SET( t1.school_id, t4.school_ids ) OR t4.school_ids IS NULL ) ",
            "WHERE",
            "t1.year_part = ${yearPart} ",
            "AND t1.quarter_num = ${quarterNum} ",
            "AND t1.lesson_type = 1 ",
            "AND t1.deleted = 0 ",
            "AND t1.subjects_id IN (${subjectsId}) ",
            "AND t1.is_last = 1 ",
            "<when test='include!=null and include!=&apos;&apos;'>",
            "<when test='include == 0'>",
            "and t4.id is null ",
            "</when>",
            "<when test='include == 1'>",
            "and t4.id is not null ",
            "</when>",
            "</when>",
            "<when test='isBeforQuarter == 0 and readingType == 1'>",
            "AND t1.reading_status IN (1,5) ",
            "</when>",
            "<when test='isBeforQuarter == 1 and readingType == 1'>",
            "AND t1.reading_status IN (1,5)",
            "</when>",
            "<when test='readingType == 2'>",
            "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and use_course_count &gt; 0)) ",
            "</when>",
            "AND t1.STATUS &lt;&gt; 3 ",
            "AND t1.deleted = 0 ",
            "<when test='gradeId!=null and gradeId!=&apos;&apos;'>",
            "and t1.grade_id = ${gradeId}",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
            "AND t2.teacher_id in(${teacherId}) ",
            "</when>",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "AND t2.year_class_id in(${yearClassIdStr}) ",
            "</when>",
            "<when test='yearClassIdStr==null or yearClassIdStr==&apos;&apos; '>",
            "AND t2.year_class_id &lt; 13 ",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "AND t1.class_type_id_new IN (${classTypeId}) ",
            "</when>",
            "GROUP BY",
            "student_id ",
            ") AS t01",
            "INNER JOIN ( SELECT * FROM edu_task WHERE deleted = 0 and task_category_id = ${taskCategoryId} and subjects_id IN (${subjectsId}) and task_course_num BETWEEN ${lessonNumEnd} and ${lessonNumEnd} ) AS t02 ON t01.year_part = t02.year_part ",
            "AND t01.quarter_num = t02.quarter_num ",
            "AND t01.subjects_id = t02.subjects_id ",
            "AND t01.class_type_id = t02.class_type_id",
            "AND t01.year_class_id = t02.year_class_id",
            "INNER JOIN (",
            "SELECT",
            "student_id,",
            "add_date,",
            "lesson_num_finish,",
            "year_class_id,",
            "course_version_id,",
            "class_type_id,",
            "year_part,",
            "quarter_num,",
            "IFNULL( lesson_num, 0 ) AS lesson_num,",
            "right_num,",
            "is_last,",
            "is_first,",
            "amend_num, ",
            "pass_rade,",
            "brush_count,",
            "lowest_shutnum",
            "FROM",
            "cha_plan ",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND quarter_num = ${quarterNum} ",
            "AND task_category_id = ${taskCategoryId} ",
            "and deleted = 0",
            ") AS t03 ON t01.year_part = t03.year_part ",
            "AND t01.quarter_num = t03.quarter_num ",
            "AND t01.student_id = t03.student_id ",
            "AND t02.year_class_id = t03.year_class_id",
            "AND t02.course_version_id = t03.course_version_id",
            "AND t02.class_type_id = t03.class_type_id ",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and t01.subjects_id IN (${subjectsId})",
            "</when>",
            "AND t02.task_course_num = t03.lesson_num",
            "and t03.is_first = 1",
            ") AS diff1 ",
            "INNER JOIN ( ",
            "SELECT ",
            "t01.school_id,",
            "t01.year_part,",
            "t01.quarter_num,",
            "t02.course_version_id,",
            "t01.grade_id,",
            "t01.grade_name,",
            "t01.teacher_id,",
            "t01.teacher_name,",
            "t01.class_type_id,",
            "t01.year_class_id,",
            "t01.student_id,",
            "t02.task_course_num AS lesson_num,",
            "t03.is_first,",
            "t03.is_last,",
            "t03.add_date,",
            "IFNULL( t03.brush_count, 0 ) AS brush_count,",
            "(CASE WHEN t03.right_num IS NOT NULL AND t03.pass_rade &gt; 0 AND ( t03.right_num + t03.amend_num ) &gt;= t03.lowest_shutnum AND ( t03.right_num / t03.lowest_shutnum )* 100 &gt;= t03.pass_rade THEN t03.lowest_shutnum ELSE t02.lowest_shutnum END ) AS lowest_shutnum,",
            "IFNULL( t03.right_num, 0 ) AS right_num, ",
            "IFNULL( t03.amend_num, 0 ) AS amend_num ",
            "FROM ( ",
            "SELECT",
            "t1.*,",
            "t1.class_type_id_new as class_type_id,",
            "t2.teacher_id,",
            "t2.`name` AS grade_name,",
            "sff.`name` AS teacher_name",
            "FROM",
            "xmy_erp_db.student_grade AS t1",
            "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id ",
            "INNER JOIN xmy_erp_db.staff AS sff ON sff.id = t2.teacher_id",
            "INNER JOIN per_student_account AS t3 ON t1.student_id = t3.student_id",
            "LEFT JOIN xmy_erp_db.rade_exclude_student AS t4 ON t4.classify_id = 0 AND t4.deleted = 0 AND t4.type = 2 AND t1.student_id = t4.student_id AND t1.year_part = t4.year_part AND t1.quarter_num = t4.quarter_num AND ( FIND_IN_SET( t1.subjects_id, t4.subjects_ids ) OR t4.subjects_ids IS NULL ) AND ( FIND_IN_SET( t1.school_id, t4.school_ids ) OR t4.school_ids IS NULL ) ",
            "WHERE",
            "t1.year_part = ${yearPart} ",
            "AND t1.quarter_num = ${quarterNum} ",
            "AND t1.lesson_type = 1 ",
            "AND t1.deleted = 0 ",
            "AND t1.subjects_id IN (${subjectsId}) ",
            "AND t1.is_last = 1 ",
            "<when test='include!=null and include!=&apos;&apos;'>",
            "<when test='include == 0'>",
            "and t4.id is null ",
            "</when>",
            "<when test='include == 1'>",
            "and t4.id is not null ",
            "</when>",
            "</when>",
            "<when test='isBeforQuarter == 0 and readingType == 1'>",
            "AND t1.reading_status IN (1,5) ",
            "</when>",
            "<when test='isBeforQuarter == 1 and readingType == 1'>",
            "AND t1.reading_status IN (1,5)",
            "</when>",
            "<when test='readingType == 2'>",
            "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and use_course_count &gt; 0)) ",
            "</when>",
            "AND t1.STATUS &lt;&gt; 3 ",
            "AND t1.deleted = 0 ",
            "<when test='gradeId!=null and gradeId!=&apos;&apos;'>",
            "and t1.grade_id = ${gradeId}",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
            "AND t2.teacher_id in(${teacherId}) ",
            "</when>",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "AND t2.year_class_id in(${yearClassIdStr}) ",
            "</when>",
            "<when test='yearClassIdStr==null or yearClassIdStr==&apos;&apos; '>",
            "AND t2.year_class_id &lt; 13 ",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "AND t1.class_type_id_new IN (${classTypeId}) ",
            "</when>",
            "GROUP BY",
            "student_id ",
            ") AS t01",
            "INNER JOIN ( SELECT * FROM edu_task WHERE deleted = 0 and task_category_id = ${taskCategoryId} and subjects_id IN (${subjectsId}) and task_course_num BETWEEN ${lessonNumStart} and ${lessonNumStart} ) AS t02 ON t01.year_part = t02.year_part ",
            "AND t01.quarter_num = t02.quarter_num ",
            "AND t01.subjects_id = t02.subjects_id ",
            "AND t01.class_type_id = t02.class_type_id",
            "AND t01.year_class_id = t02.year_class_id",
            "INNER JOIN (",
            "SELECT",
            "student_id,",
            "add_date,",
            "lesson_num_finish,",
            "year_class_id,",
            "course_version_id,",
            "class_type_id,",
            "year_part,",
            "quarter_num,",
            "IFNULL( lesson_num, 0 ) AS lesson_num,",
            "right_num,",
            "is_last,",
            "is_first,",
            "amend_num, ",
            "pass_rade,",
            "brush_count,",
            "lowest_shutnum",
            "FROM",
            "cha_plan ",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND quarter_num = ${quarterNum} ",
            "AND task_category_id = ${taskCategoryId} ",
            "and deleted = 0",
            ") AS t03 ON t01.year_part = t03.year_part ",
            "AND t01.quarter_num = t03.quarter_num ",
            "AND t01.student_id = t03.student_id ",
            "AND t02.year_class_id = t03.year_class_id",
            "AND t02.course_version_id = t03.course_version_id",
            "AND t02.class_type_id = t03.class_type_id ",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and t01.subjects_id IN (${subjectsId})",
            "</when>",
            "AND t02.task_course_num = t03.lesson_num",
            "and t03.is_first = 1",
            ") AS diff2 ON diff1.student_id = diff2.student_id ",
            ") AS diff01 ON diff01.teacher_id = t1.teacher_id ",
            "AND ( find_in_set( diff01.year_class_id, t1.year_class_id_str ) OR t1.year_class_id_str = '' ) ",
            "AND ( find_in_set( diff01.school_id, t1.school_id_str ) OR t1.school_id_str = '' ) ",
            "WHERE 1=1 ",
            "<when test='startDate!=null and startDate!=&apos;&apos; and endDate!=null and endDate!=&apos;&apos;'>",// 普通
            "and add_date BETWEEN '${startDate}' AND '${endDate}'",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
            "AND diff01.teacher_id in(${teacherId}) ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 1'>",// 普通
            "AND right_rade &lt; right_rade2 ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 2'>",// 进步
            "AND right_rade &gt;= right_rade2 ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 3'>",// 优秀
            "AND right_rade &gt;= 90 ",
            "</when>",
            "<when test='passType!=null and passType!=&apos;&apos; and passType == 4'>",// 学霸
            "AND right_rade &gt;= 100 ",
            "</when>",
            "ORDER BY student_id ASC",
            "</script>"})
    public IPage<ChaPlan> getHonorTeamDetails(IPage<?> page,
                                              @Param("yearPart") String yearPart,
                                              @Param("quarterNum") String quarterNum,
                                              @Param("yearClassIdStr") String yearClassIdStr,
                                              @Param("lessonNumStart") String lessonNumStart,
                                              @Param("lessonNumEnd") String lessonNumEnd,
                                              @Param("classTypeId") String classTypeId,
                                              @Param("readingType") String readingType,
                                              @Param("subjectsId") String subjectsId,
                                              @Param("isBeforQuarter") String isBeforQuarter,
                                              @Param("teacherId") String teacherId,
                                              @Param("name") String name,
                                              @Param("include") String include,
                                              @Param("taskCategoryId") Integer taskCategoryId,
                                              @Param("classify") String classify,
                                              @Param("trackType") String trackType,
                                              @Param("teamId") String teamId,
                                              @Param("gradeId") String gradeId,
                                              @Param("startDate") String startDate,
                                              @Param("endDate") String endDate

    );

    /**
     * 数学积分列表
     */
    @Select({"<script>",
            "SELECT t.*, ",
            "<when test='type == 6'>",
                "t1.pid AS schoolPid,",
                "t1.school_name,",
            "</when>",
            "<when test='listState == 2'>",
                "GROUP_CONCAT( DISTINCT lesson_num ) AS lessonNumNot,",
            "</when>",
            "SUM( integral ) AS integral_all,",
            "SUM( CASE WHEN DATE ( created_at ) BETWEEN '${startDate}' AND '${endDate}' THEN integral WHEN DATE ( integral_add_date_time ) BETWEEN '${startDate}' AND '${endDate}' THEN integral ELSE 0 END ) AS integral_all_date,",
            "IFNULL( CONCAT( ROUND( AVG( rate ), 2 ), '%' ), '0%' ) AS rate_avg",
            "FROM ( ",
            "<when test='type == 6'>",
                "SELECT * FROM xmy_erp_db.school_quarter WHERE year_part = ${yearPart} AND quarter_num = ${quarterNum} AND deleted = 0 ) AS t1 ",
                "INNER JOIN (",
                "SELECT * FROM (",
            "</when>",
            "WITH plan_tb AS (",
            "SELECT",
            "t01.id,",
            "t01.subjects_id,",
            "t01.school_id,",
            "t01.year_part,",
            "t01.quarter_num,",
            "t02.course_version_id,",
            "t01.grade_id,",
            "t01.teacher_id,",
            "t01.teacher_name,",
            "t01.student_name,",
            "t01.grade_name,",
            "t01.class_type_id,",
            "t01.year_class_id,",
            "t01.student_id,",
            "t01.linkman_phone,",
            "t02.task_course_num AS lesson_num,",
            "( CASE WHEN t03.right_num IS NOT NULL AND t03.pass_rade &gt; 0",
            "AND ( t03.right_num + t03.amend_num ) &gt;= t03.lowest_shutnum ",
            "AND ( t03.right_num / t03.lowest_shutnum )* 100 &gt;= t03.pass_rade",
            "THEN t03.lowest_shutnum ELSE t02.lowest_shutnum END ) AS lowest_shutnum,",
            "IFNULL( t03.right_num, 0 ) AS right_num,",
            "IFNULL( t03.amend_num, 0 ) AS amend_num,",
            "t03.created_at, ",
            "IFNULL( t03.integral, 0 ) AS cha_integral,",
            "t03.integral_add_date_time ",
            "FROM",
            "(",
            "SELECT",
            "t1.*,",
            "t1.class_type_id_new AS class_type_id,",
            "t2.teacher_id,",
            "t5.linkman_phone,",
            "t5.`name` AS student_name,",
            "t6.`name` AS teacher_name,",
            "t2.`name` AS grade_name ",
            "FROM",
            "xmy_erp_db.student_grade AS t1",
            "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id ",
            "INNER JOIN per_student_account AS t3 ON t1.student_id = t3.student_id",
            "INNER JOIN xmy_erp_db.student AS t5 ON t1.student_id = t5.id ",
            "LEFT JOIN xmy_erp_db.rade_exclude_student AS t4 ON t4.classify_id = 0 AND t4.deleted = 0 AND t4.type = 2 AND t1.student_id = t4.student_id AND t1.year_part = t4.year_part AND t1.quarter_num = t4.quarter_num AND ( FIND_IN_SET( t1.subjects_id, t4.subjects_ids ) OR t4.subjects_ids IS NULL ) AND ( FIND_IN_SET( t1.school_id, t4.school_ids ) OR t4.school_ids IS NULL ) ",
            "LEFT JOIN xmy_erp_db.staff AS t6 ON t2.teacher_id = t6.id ",
            "WHERE",
            "t1.year_part = ${yearPart} ",
            "AND t1.quarter_num = ${quarterNum}",
            "AND t1.lesson_type = 1",
            "AND t1.deleted = 0 ",
            "AND t1.subjects_id = ${subjectsId} ",
            "AND t1.is_last = 1 ",
            "AND t4.id is null ",
            "AND t1.STATUS &lt;&gt; 3 ",
            "AND t1.deleted = 0 ",
            "<when test='include!=null and include!=&apos;&apos;'>",
                "<when test='include == 0'>",
                    "AND t4.id is null ",
                "</when>",
                "<when test='include == 1'>",
                    "AND t4.id is not null ",
                "</when>",
            "</when>",
            "<when test='isBeforQuarter == 0 and readingType == 1'>",
                "AND t1.reading_status IN (1,5) ",
            "</when>",
            "<when test='isBeforQuarter == 1 and readingType == 1'>",
                "AND t1.reading_status IN (1,5)",
            "</when>",
            "<when test='readingType == 2'>",
                "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and use_course_count > 0)) ",
            "</when>",
            "<when test='schoolId!=null and schoolId!=&apos;&apos;'>",
                "AND t1.school_id IN(${schoolId})",
            "</when>",
            "<when test='yearClassId!=null and yearClassId!=&apos;&apos; '>",
                "AND t2.year_class_id IN(${yearClassId})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
                "AND t1.class_type_id_new IN (${classTypeId})",
            "</when>",
            "<when test='type ==3'>",
                "AND t2.teacher_id in(select admin_id from xmy_erp_db.role_admin where role_id = 1568160887369994242) ",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; and type != 4'>",
                "AND t2.teacher_id = ${teacherId}",
            "</when>",
            "GROUP BY",
            "student_id ",
            ") AS t01",
            "INNER JOIN ( SELECT * FROM edu_task WHERE deleted = 0 and task_category_id = ${taskCategoryId} and subjects_id = ${subjectsId} and task_course_num BETWEEN ${lessonNumStart} and ${lessonNumEnd}) AS t02 ON t01.year_part = t02.year_part ",
            "AND t01.quarter_num = t02.quarter_num ",
            "AND t01.subjects_id = t02.subjects_id ",
            "AND t01.class_type_id = t02.class_type_id",
            "AND t01.year_class_id = t02.year_class_id",
            "<when test= 'inType == 2'>",
            "INNER",
            "</when>",
            "<when test= 'inType != 2'>",
            "LEFT",
            "</when>",
            "JOIN (",
            "SELECT ",
            "student_id,",
            "add_date,",
            "lesson_num_finish,",
            "year_class_id,",
            "course_version_id,",
            "class_type_id,",
            "year_part,",
            "quarter_num,",
            "IFNULL( lesson_num, 0 ) AS lesson_num,",
            "right_num,",
            "is_last,",
            "is_first,",
            "amend_num, ",
            "lowest_shutnum, ",
            "brush_count, ",
            "pass_rade,",
            "pass_date_time, ",
            "created_at,",
            "IFNULL( integral, 0 ) AS integral,",
            "integral_add_date_time ",
            "FROM",
            "cha_plan ",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND quarter_num = ${quarterNum}",
            "AND task_category_id = ${taskCategoryId}",
            "and deleted = 0",
            ") AS t03 ON t01.year_part = t03.year_part ",
            "AND t01.quarter_num = t03.quarter_num ",
            "AND t01.student_id = t03.student_id ",
            "AND t02.year_class_id = t03.year_class_id ",
            "AND t02.class_type_id = t03.class_type_id ",
            "AND t02.course_version_id = t03.course_version_id",
            "<when test='courseVersionId!=null and courseVersionId!=&apos;&apos;'>",
            "and t02.course_version_id = ${courseVersionId}",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and t01.subjects_id = ${subjectsId}",
            "</when>",
            "AND t02.task_course_num = t03.lesson_num",
            "AND t03.is_first = 1 ",
            ")",

            // 数学正确率
            "SELECT",
            "*,",
            "1 AS mold_type,",
            "CASE WHEN lowest_shutnum &gt; 0 THEN CONCAT( ROUND( IFNULL( right_num / lowest_shutnum, 0 ) * 100, 2 ), '%' ) ELSE'0%' END AS rate,",
            "CASE ",
            // 小学
            "WHEN year_class_id &gt;= 3 AND year_class_id &lt;= 6 AND right_num &gt;= 60 AND right_num &lt;= 69.5 THEN 1 ",
            "WHEN year_class_id &gt;= 3 AND year_class_id &lt;= 6 AND right_num &gt;= 70 AND right_num &lt;= 79.5 THEN 2 ",
            "WHEN year_class_id &gt;= 3 AND year_class_id &lt;= 6 AND right_num &gt;= 80 AND right_num &lt;= 89.5 THEN 3 ",
            "WHEN year_class_id &gt;= 3 AND year_class_id &lt;= 6 AND right_num &gt;= 90 AND right_num &lt;= 99.5 THEN 4 ",
            "WHEN year_class_id &gt;= 3 AND year_class_id &lt;= 6 AND right_num &gt;= 100 THEN 5 ",
            // 初中
            "WHEN year_class_id &gt;= 7 AND year_class_id &lt;= 9 AND right_num &gt;= 70 AND right_num &lt;= 79.5 THEN 1 ",
            "WHEN year_class_id &gt;= 7 AND year_class_id &lt;= 9 AND right_num &gt;= 80 AND right_num &lt;= 89.5 THEN 2 ",
            "WHEN year_class_id &gt;= 7 AND year_class_id &lt;= 9 AND right_num &gt;= 90 AND right_num &lt;= 99.5 THEN 3 ",
            "WHEN year_class_id &gt;= 7 AND year_class_id &lt;= 9 AND right_num &gt;= 100 AND right_num &lt;= 109.5 THEN 4 ",
            "WHEN year_class_id &gt;= 7 AND year_class_id &lt;= 9 AND right_num &gt;= 110 THEN 5 ",
            "ELSE 0 ",
            "END AS integral ",
            "FROM plan_tb",

            "UNION ALL",

            // 数学通关率
            "SELECT",
            "*,",
            "2 AS mold_type,",
            "CASE WHEN right_num + amend_num &gt;= lowest_shutnum THEN '100%' ELSE '0%' END AS rate,",
            "CASE ",
            "WHEN year_class_id &gt;= 3 AND year_class_id &lt;= 6 AND (right_num + amend_num &gt;= lowest_shutnum) THEN 1",
            "WHEN year_class_id &gt;= 7 AND year_class_id &lt;= 9 AND (right_num + amend_num &gt;= lowest_shutnum) THEN 1",
            "ELSE 0",
            "END AS integral ",
            "FROM plan_tb ",

            "UNION ALL",

            // 费曼学习积分
            "SELECT",
            "*,",
            "3 AS mold_type,",
            "cha_integral AS rate,",
            "cha_integral AS integral ",
            "FROM plan_tb",
            "<when test='type != 6'>",
                ") AS t ",
                "WHERE 1=1",
                "<when test='moldType!=null and moldType!=&apos;&apos; and moldType!=0'>",
                "AND t.mold_type IN (${moldType}) ",
                "</when>",
            "</when>",
            "<when test='type == 6'>",
                    ") AS tt",
                    "WHERE 1=1",
                    "<when test='moldType!=null and moldType!=&apos;&apos; and moldType!=0'>",
                        "AND tt.mold_type IN (${moldType}) ",
                    "</when>",
                ") AS t ON t1.school_id = t.school_id ",
            "</when>",
            "GROUP BY ",
            "<when test='type == 1 or type == 3'>",
                "teacher_id",
            "</when>",
            "<when test='type == 2'>",
                "school_id,teacher_id",
            "</when>",
            "<when test='type == 4 or type == 6'>",
                "school_id",
            "</when>",
            "<when test='listState == 1'>",
                ",grade_id,mold_type,lesson_num ",
            "</when>",
            "<when test='listState == 2'>",
                ",grade_id ",
            "</when>",
            "<when test='listState == 3'>",
                ",grade_id,lesson_num ",
            "</when>",
            "ORDER BY grade_id,lesson_num,mold_type ASC;",
            "</script>"})
    public List<ChaPlan> getPassRadeIntegralList(
            @Param("yearPart") String yearPart,
            @Param("quarterNum") String quarterNum,
            @Param("schoolId") String schoolId,
            @Param("teacherId") String teacherId,
            @Param("yearClassId") String yearClassId,
            @Param("subjectsId") Long subjectsId,
            @Param("classTypeId") String classTypeId,
            @Param("readingType") String readingType,
            @Param("courseVersionId") Long courseVersionId,
            @Param("isBeforQuarter") String isBeforQuarter,
            @Param("include") String include,
            @Param("taskCategoryId") String taskCategoryId,
            @Param("lessonNumStart") String lessonNumStart,
            @Param("lessonNumEnd") String lessonNumEnd,
            @Param("startDate") String startDate,
            @Param("endDate") String endDate,
            @Param("type") String type,
            @Param("inType") String inType,// 1、全部，2已录
            @Param("listState") String listState,
            @Param("moldType") String moldType  // 1、正确率，2、通关率，3、费曼学习积分
    );

    /**
     * 数学积分详情
     */
    @Select({"<script>",
            "SELECT * ",
            "<when test='listState == 0'>",
                ",CASE WHEN DATE ( created_at ) BETWEEN '${startDate}' AND '${endDate}' THEN integral WHEN DATE ( integral_add_date_time ) BETWEEN '${startDate}' AND '${endDate}' THEN integral ELSE 0 END AS integral_all_date ",
            "</when>",

            "<when test='listState == 1 || listState == 2 '>",
                ",GROUP_CONCAT( DISTINCT lesson_num ) AS lessonNumNot,",
                "SUM(integral) AS integral_all,",
                "SUM( CASE WHEN DATE ( created_at ) BETWEEN '${startDate}' AND '${endDate}' THEN integral WHEN DATE ( integral_add_date_time ) BETWEEN '${startDate}' AND '${endDate}' THEN integral ELSE 0 END ) AS integral_all_date ",
            "</when>",

            "FROM (",
                "WITH plan_tb AS (",
                    "SELECT",
                    "t01.id,",
                    "t01.subjects_id,",
                    "t01.school_id,",
                    "t01.year_part,",
                    "t01.quarter_num,",
                    "t02.course_version_id,",
                    "t01.grade_id,",
                    "t01.teacher_id,",
                    "t01.teacher_name,",
                    "t01.student_name,",
                    "t01.grade_name,",
                    "t01.class_type_id,",
                    "t01.year_class_id,",
                    "t01.student_id,",
                    "t01.linkman_phone,",
                    "t02.task_course_num AS lesson_num,",
                    "( CASE WHEN t03.right_num IS NOT NULL AND t03.pass_rade &gt; 0",
                    "AND ( t03.right_num + t03.amend_num ) &gt;= t03.lowest_shutnum ",
                    "AND ( t03.right_num / t03.lowest_shutnum )* 100 &gt;= t03.pass_rade",
                    "THEN t03.lowest_shutnum ELSE t02.lowest_shutnum END ) AS lowest_shutnum,",
                    "IFNULL( t03.right_num, 0 ) AS right_num,",
                    "IFNULL( t03.amend_num, 0 ) AS amend_num,",
                    "t03.created_at, ",
                    "IFNULL( t03.integral, 0 ) AS cha_integral,",
                    "t03.integral_add_date_time ",
                    "FROM",
                    "(",
                        "SELECT",
                        "t1.*,",
                        "t1.class_type_id_new AS class_type_id,",
                        "t2.teacher_id,",
                        "t5.linkman_phone,",
                        "t5.`name` AS student_name,",
                        "t6.`name` AS teacher_name,",
                        "t2.`name` AS grade_name",
                        "FROM",
                        "xmy_erp_db.student_grade AS t1",
                        "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id ",
                        "INNER JOIN per_student_account AS t3 ON t1.student_id = t3.student_id",
                        "INNER JOIN xmy_erp_db.student AS t5 ON t1.student_id = t5.id ",
                        "LEFT JOIN xmy_erp_db.rade_exclude_student AS t4 ON t4.classify_id = 0 AND t4.deleted = 0 AND t4.type = 2 AND t1.student_id = t4.student_id AND t1.year_part = t4.year_part AND t1.quarter_num = t4.quarter_num AND ( FIND_IN_SET( t1.subjects_id, t4.subjects_ids ) OR t4.subjects_ids IS NULL ) AND ( FIND_IN_SET( t1.school_id, t4.school_ids ) OR t4.school_ids IS NULL ) ",
                        "LEFT JOIN xmy_erp_db.staff AS t6 ON t2.teacher_id = t6.id ",
                        "WHERE",
                        "t1.year_part = ${yearPart} ",
                        "AND t1.quarter_num = ${quarterNum}",
                        "AND t1.lesson_type = 1",
                        "AND t1.deleted = 0 ",
                        "AND t1.subjects_id = ${subjectsId} ",
                        "AND t1.is_last = 1 ",
                        "AND t4.id is null ",
                        "AND t1.STATUS &lt;&gt; 3 ",
                        "AND t1.deleted = 0 ",
                        "<when test='include!=null and include!=&apos;&apos;'>",
                            "<when test='include == 0'>",
                                "AND t4.id is null ",
                            "</when>",
                            "<when test='include == 1'>",
                                "AND t4.id is not null ",
                            "</when>",
                        "</when>",
                        "<when test='isBeforQuarter == 0 and readingType == 1'>",
                            "AND t1.reading_status IN (1,5) ",
                        "</when>",
                        "<when test='isBeforQuarter == 1 and readingType == 1'>",
                            "AND t1.reading_status IN (1,5)",
                        "</when>",
                        "<when test='readingType == 2'>",
                            "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and use_course_count > 0)) ",
                        "</when>",
                        "<when test='gradeId!=null and gradeId!=&apos;&apos;'>",
                            "AND t1.grade_id = ${gradeId}",
                        "</when>",
                        "<when test='studentName!=null and studentName!=&apos;&apos;'>",
                            "AND t5.`name` LIKE '%${studentName}%' ",
                        "</when>",
                        "<when test='schoolId!=null and schoolId!=&apos;&apos;'>",
                            "AND t1.school_id IN(${schoolId})",
                        "</when>",
                        "<when test='yearClassId!=null and yearClassId!=&apos;&apos; '>",
                            "AND t2.year_class_id IN(${yearClassId})",
                        "</when>",
                        "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
                            "AND t1.class_type_id_new IN (${classTypeId})",
                        "</when>",
                        "<when test='teacherId!=null and teacherId!=&apos;&apos; and type != 4'>",
                            "AND t2.teacher_id = ${teacherId}",
                        "</when>",
                        "<when test='studentId!=null and studentId!=&apos;&apos;'>",
                            "AND t1.student_id = ${studentId}",
                        "</when>",
                        "GROUP BY",
                        "student_id ",
                    ") AS t01",
                    "INNER JOIN ( SELECT * FROM edu_task WHERE deleted = 0 and task_category_id = ${taskCategoryId} and subjects_id = ${subjectsId} and task_course_num BETWEEN ${lessonNumStart} and ${lessonNumEnd}) AS t02 ON t01.year_part = t02.year_part ",
                    "AND t01.quarter_num = t02.quarter_num ",
                    "AND t01.subjects_id = t02.subjects_id ",
                    "AND t01.class_type_id = t02.class_type_id",
                    "AND t01.year_class_id = t02.year_class_id",
                    "<when test= 'inType == 2'>",
                    "INNER",
                    "</when>",
                    "<when test= 'inType != 2'>",
                    "LEFT",
                    "</when>",
                    "JOIN (",
                        "SELECT ",
                        "student_id,",
                        "add_date,",
                        "lesson_num_finish,",
                        "year_class_id,",
                        "course_version_id,",
                        "class_type_id,",
                        "year_part,",
                        "quarter_num,",
                        "IFNULL( lesson_num, 0 ) AS lesson_num,",
                        "right_num,",
                        "is_last,",
                        "is_first,",
                        "amend_num, ",
                        "lowest_shutnum, ",
                        "brush_count, ",
                        "pass_rade,",
                        "pass_date_time, ",
                        "created_at,",
                        "IFNULL( integral, 0 ) AS integral,",
                        "integral_add_date_time ",
                        "FROM",
                        "cha_plan ",
                        "WHERE",
                        "year_part = ${yearPart} ",
                        "AND quarter_num = ${quarterNum}",
                        "AND task_category_id = ${taskCategoryId}",
                        "and deleted = 0",
                    ") AS t03 ON t01.year_part = t03.year_part ",
                    "AND t01.quarter_num = t03.quarter_num ",
                    "AND t01.student_id = t03.student_id ",
                    "AND t02.year_class_id = t03.year_class_id ",
                    "AND t02.class_type_id = t03.class_type_id ",
                    "AND t02.course_version_id = t03.course_version_id",
                    "<when test='courseVersionId!=null and courseVersionId!=&apos;&apos;'>",
                        "and t02.course_version_id = ${courseVersionId}",
                    "</when>",
                    "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
                        "and t01.subjects_id = ${subjectsId}",
                    "</when>",
                    "AND t02.task_course_num = t03.lesson_num",
                    "AND t03.is_first = 1 ",
                ")",

                // 数学正确率
                "SELECT",
                "*,",
                "1 AS mold_type,",
                "CASE WHEN lowest_shutnum &gt; 0 THEN CONCAT(ROUND(IFNULL(right_num / lowest_shutnum, 0) * 100, 2), '%') ELSE '0%' END AS rate,",
                "CASE ",
                // 小学
                "WHEN year_class_id &gt;= 3 AND year_class_id &lt;= 6 AND right_num &gt;= 60 AND right_num &lt;= 69.5 THEN 1 ",
                "WHEN year_class_id &gt;= 3 AND year_class_id &lt;= 6 AND right_num &gt;= 70 AND right_num &lt;= 79.5 THEN 2 ",
                "WHEN year_class_id &gt;= 3 AND year_class_id &lt;= 6 AND right_num &gt;= 80 AND right_num &lt;= 89.5 THEN 3 ",
                "WHEN year_class_id &gt;= 3 AND year_class_id &lt;= 6 AND right_num &gt;= 90 AND right_num &lt;= 99.5 THEN 4 ",
                "WHEN year_class_id &gt;= 3 AND year_class_id &lt;= 6 AND right_num &gt;= 100 THEN 5 ",
                // 初中
                "WHEN year_class_id &gt;= 7 AND year_class_id &lt;= 9 AND right_num &gt;= 70 AND right_num &lt;= 79.5 THEN 1 ",
                "WHEN year_class_id &gt;= 7 AND year_class_id &lt;= 9 AND right_num &gt;= 80 AND right_num &lt;= 89.5 THEN 2 ",
                "WHEN year_class_id &gt;= 7 AND year_class_id &lt;= 9 AND right_num &gt;= 90 AND right_num &lt;= 99.5 THEN 3 ",
                "WHEN year_class_id &gt;= 7 AND year_class_id &lt;= 9 AND right_num &gt;= 100 AND right_num &lt;= 109.5 THEN 4 ",
                "WHEN year_class_id &gt;= 7 AND year_class_id &lt;= 9 AND right_num &gt;= 110 THEN 5 ",
                "ELSE 0 ",
                "END AS integral ",
                "FROM plan_tb",

                "UNION ALL",

                // 数学通关率
                "SELECT",
                "*,",
                "2 AS mold_type,",
                "CASE WHEN right_num + amend_num &gt;= lowest_shutnum THEN '100%' ELSE '0%' END AS rate,",
                "CASE ",
                "WHEN year_class_id &gt;= 3 AND year_class_id &lt;= 6 AND (right_num + amend_num &gt;= lowest_shutnum) THEN 1",
                "WHEN year_class_id &gt;= 7 AND year_class_id &lt;= 9 AND (right_num + amend_num &gt;= lowest_shutnum) THEN 1",
                "ELSE 0",
                "END AS integral ",
                "FROM plan_tb ",

                "UNION ALL",

                // 费曼学习积分
                "SELECT",
                "*,",
                "3 AS mold_type,",
                "cha_integral AS rate,",
                "cha_integral AS integral ",
                "FROM plan_tb",
            ") AS t ",
            "WHERE 1=1",
            "<when test='moldType!=null and moldType!=&apos;&apos; and moldType!=0'>",
                "AND t.mold_type IN (${moldType}) ",
            "</when>",
//            "<when test='startDate!=null and startDate!=&apos;&apos; and endDate!=null and endDate!=&apos;&apos; '>",
//                "AND (( DATE(created_at) BETWEEN '${startDate}' AND '${endDate}' ) OR ( DATE(integral_add_date_time) BETWEEN '${startDate}' AND '${endDate}' ))",
//            "</when>",
            "<when test='listState == 1'>",
                "GROUP BY student_id ",
            "</when>",
            "<when test='listState == 2'>",
                "GROUP BY student_id,lesson_num ",
            "</when>",
            "ORDER BY student_id,lesson_num,mold_type ASC ",
            "</script>"})
    public IPage<ChaPlan> getPassRadeIntegralDetail(IPage<?> page,
                                                    @Param("yearPart") String yearPart,
                                                    @Param("quarterNum") String quarterNum,
                                                    @Param("schoolId") String schoolId,
                                                    @Param("teacherId") String teacherId,
                                                    @Param("studentId") String studentId,
                                                    @Param("yearClassId") String yearClassId,
                                                    @Param("subjectsId") Long subjectsId,
                                                    @Param("gradeId") String gradeId,
                                                    @Param("classTypeId") String classTypeId,
                                                    @Param("readingType") String readingType,
                                                    @Param("courseVersionId") Long courseVersionId,
                                                    @Param("isBeforQuarter") String isBeforQuarter,
                                                    @Param("studentName") String studentName,
                                                    @Param("include") String include,
                                                    @Param("taskCategoryId") String taskCategoryId,
                                                    @Param("lessonNumStart") String lessonNumStart,
                                                    @Param("lessonNumEnd") String lessonNumEnd,
                                                    @Param("startDate") String startDate,
                                                    @Param("endDate") String endDate,
                                                    @Param("type") String type,
                                                    @Param("inType") String inType,// 1、全部，2已录
                                                    @Param("moldType") String moldType,  // 1、正确率，2、通关率，3、费曼学习积分
                                                    @Param("listState") String listState
    );

    /**
     * 数学积分战队列表
     */
    @Select({"<script>",
            "SELECT t.*,team_name,team_id,team_pid, ",
            "<when test='listState == 2'>",
                "GROUP_CONCAT( DISTINCT lesson_num ) AS lessonNumNot,",
            "</when>",
            "SUM( integral ) AS integral_all,",
            "SUM( CASE WHEN DATE ( t.created_at ) BETWEEN '${startDate}' AND '${endDate}' THEN integral WHEN DATE ( integral_add_date_time ) BETWEEN '${startDate}' AND '${endDate}' THEN integral ELSE 0 END ) AS integral_all_date, ",
            "IFNULL( CONCAT( ROUND( AVG( rate ), 2 ), '%' ), '0%' ) AS rate_avg",
            "FROM ( ",
                "SELECT ",
                "td.*, ",
                "td.sourse_id AS teacher_id,",
                "tm.team_name,",
                "tm.id AS team_id,",
                "tm.pid AS team_pid ",
                "FROM",
                "xmy_erp_db.track_market AS tm",
                "LEFT JOIN xmy_erp_db.track_detail AS td ON tm.id = td.track_id AND tm.deleted = td.deleted ",
                "WHERE ",
                "tm.classify = ${classify} ",
                "AND tm.track_type = ${trackType} ",
                "AND tm.`status` = 1 ",
                "AND tm.deleted = 0 ",
                "AND tm.year_part = ${yearPart} ",
                "AND tm.quarter_num = ${quarterNum} ",
                "<when test='teamId!=null and teamId!=&apos;&apos; '>",
                    "AND tm.id in(${teamId})",
                "</when>",
                "GROUP BY tm.id,td.sourse_id ",
            ") AS t1 ",
            "LEFT JOIN ( ",
            "SELECT * FROM ( ",
                "WITH plan_tb AS (",
                "SELECT",
                "t01.id,",
                "t01.subjects_id,",
                "t01.school_id,",
                "t01.year_part,",
                "t01.quarter_num,",
                "t02.course_version_id,",
                "t01.grade_id,",
                "t01.teacher_id,",
                "t01.teacher_name,",
                "t01.student_name,",
                "t01.grade_name,",
                "t01.class_type_id,",
                "t01.year_class_id,",
                "t01.student_id,",
                "t01.linkman_phone,",
                "t02.task_course_num AS lesson_num,",
                "( CASE WHEN t03.right_num IS NOT NULL AND t03.pass_rade &gt; 0",
                "AND ( t03.right_num + t03.amend_num ) &gt;= t03.lowest_shutnum ",
                "AND ( t03.right_num / t03.lowest_shutnum )* 100 &gt;= t03.pass_rade",
                "THEN t03.lowest_shutnum ELSE t02.lowest_shutnum END ) AS lowest_shutnum,",
                "IFNULL( t03.right_num, 0 ) AS right_num,",
                "IFNULL( t03.amend_num, 0 ) AS amend_num,",
                "t03.created_at, ",
                "IFNULL( t03.integral, 0 ) AS cha_integral,",
                "t03.integral_add_date_time ",
                "FROM",
                "(",
                    "SELECT",
                    "t1.*,",
                    "t1.class_type_id_new AS class_type_id,",
                    "t2.teacher_id,",
                    "t5.linkman_phone,",
                    "t5.`name` AS student_name,",
                    "t6.`name` AS teacher_name,",
                    "t2.`name` AS grade_name",
                    "FROM",
                    "xmy_erp_db.student_grade AS t1",
                    "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id ",
                    "INNER JOIN per_student_account AS t3 ON t1.student_id = t3.student_id",
                    "INNER JOIN xmy_erp_db.student AS t5 ON t1.student_id = t5.id ",
                    "LEFT JOIN xmy_erp_db.rade_exclude_student AS t4 ON t4.classify_id = 0 AND t4.deleted = 0 AND t4.type = 2 AND t1.student_id = t4.student_id AND t1.year_part = t4.year_part AND t1.quarter_num = t4.quarter_num AND ( FIND_IN_SET( t1.subjects_id, t4.subjects_ids ) OR t4.subjects_ids IS NULL ) AND ( FIND_IN_SET( t1.school_id, t4.school_ids ) OR t4.school_ids IS NULL ) ",
                    "LEFT JOIN xmy_erp_db.staff AS t6 ON t2.teacher_id = t6.id ",
                    "WHERE",
                    "t1.year_part = ${yearPart} ",
                    "AND t1.quarter_num = ${quarterNum}",
                    "AND t1.lesson_type = 1",
                    "AND t1.deleted = 0 ",
                    "AND t1.subjects_id = ${subjectsId} ",
                    "AND t1.is_last = 1 ",
                    "AND t4.id is null ",
                    "AND t1.STATUS &lt;&gt; 3 ",
                    "AND t1.deleted = 0 ",
                    "<when test='include!=null and include!=&apos;&apos;'>",
                        "<when test='include == 0'>",
                            "and t4.id is null ",
                        "</when>",
                        "<when test='include == 1'>",
                            "and t4.id is not null ",
                        "</when>",
                    "</when>",
                    "<when test='isBeforQuarter == 0 and readingType == 1'>",
                        "AND t1.reading_status IN (1,5) ",
                    "</when>",
                    "<when test='isBeforQuarter == 1 and readingType == 1'>",
                        "AND t1.reading_status IN (1,5)",
                    "</when>",
                    "<when test='readingType == 2'>",
                        "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and use_course_count > 0)) ",
                    "</when>",
                    "<when test='schoolId!=null and schoolId!=&apos;&apos;'>",
                        "AND t1.school_id IN(${schoolId})",
                    "</when>",
                    "<when test='yearClassId!=null and yearClassId!=&apos;&apos; '>",
                        "AND t2.year_class_id IN(${yearClassId})",
                    "</when>",
                    "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
                        "AND t1.class_type_id_new IN (${classTypeId})",
                    "</when>",
                    "<when test='teacherId!=null and teacherId!=&apos;&apos; and type != 4'>",
                        "AND t2.teacher_id = ${teacherId}",
                    "</when>",
                    "GROUP BY",
                    "student_id ",
                ") AS t01",
                "INNER JOIN ( SELECT * FROM edu_task WHERE deleted = 0 and task_category_id = ${taskCategoryId} and subjects_id = ${subjectsId} and task_course_num BETWEEN ${lessonNumStart} and ${lessonNumEnd}) AS t02 ON t01.year_part = t02.year_part ",
                "AND t01.quarter_num = t02.quarter_num ",
                "AND t01.subjects_id = t02.subjects_id ",
                "AND t01.class_type_id = t02.class_type_id",
                "AND t01.year_class_id = t02.year_class_id",
                "<when test= 'inType == 2'>",
                    "INNER",
                "</when>",
                "<when test= 'inType != 2'>",
                    "LEFT",
                "</when>",
                "JOIN (",
                    "SELECT ",
                    "student_id,",
                    "add_date,",
                    "lesson_num_finish,",
                    "year_class_id,",
                    "course_version_id,",
                    "class_type_id,",
                    "year_part,",
                    "quarter_num,",
                    "IFNULL( lesson_num, 0 ) AS lesson_num,",
                    "right_num,",
                    "is_last,",
                    "is_first,",
                    "amend_num, ",
                    "lowest_shutnum, ",
                    "brush_count, ",
                    "pass_rade,",
                    "pass_date_time, ",
                    "created_at,",
                    "IFNULL( integral, 0 ) AS integral,",
                    "integral_add_date_time ",
                    "FROM",
                    "cha_plan ",
                    "WHERE",
                    "year_part = ${yearPart} ",
                    "AND quarter_num = ${quarterNum}",
                    "AND task_category_id = ${taskCategoryId}",
                    "and deleted = 0",
                ") AS t03 ON t01.year_part = t03.year_part ",
                "AND t01.quarter_num = t03.quarter_num ",
                "AND t01.student_id = t03.student_id ",
                "AND t02.year_class_id = t03.year_class_id ",
                "AND t02.class_type_id = t03.class_type_id ",
                "AND t02.course_version_id = t03.course_version_id",
                "<when test='courseVersionId!=null and courseVersionId!=&apos;&apos;'>",
                    "AND t02.course_version_id = ${courseVersionId}",
                "</when>",
                "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
                    "AND t01.subjects_id = ${subjectsId}",
                "</when>",
                "AND t02.task_course_num = t03.lesson_num",
                "AND t03.is_first = 1 ",
                ")",

                // 数学正确率
                "SELECT",
                "*,",
                "1 AS mold_type,",
                "CASE WHEN lowest_shutnum &gt; 0 THEN CONCAT(ROUND(IFNULL(right_num / lowest_shutnum, 0) * 100, 2), '%') ELSE '0%' END AS rate,",
                "CASE ",
                // 小学
                "WHEN year_class_id &gt;= 3 AND year_class_id &lt;= 6 AND right_num &gt;= 60 AND right_num &lt;= 69.5 THEN 1 ",
                "WHEN year_class_id &gt;= 3 AND year_class_id &lt;= 6 AND right_num &gt;= 70 AND right_num &lt;= 79.5 THEN 2 ",
                "WHEN year_class_id &gt;= 3 AND year_class_id &lt;= 6 AND right_num &gt;= 80 AND right_num &lt;= 89.5 THEN 3 ",
                "WHEN year_class_id &gt;= 3 AND year_class_id &lt;= 6 AND right_num &gt;= 90 AND right_num &lt;= 99.5 THEN 4 ",
                "WHEN year_class_id &gt;= 3 AND year_class_id &lt;= 6 AND right_num &gt;= 100 THEN 5 ",
                // 初中
                "WHEN year_class_id &gt;= 7 AND year_class_id &lt;= 9 AND right_num &gt;= 70 AND right_num &lt;= 79.5 THEN 1 ",
                "WHEN year_class_id &gt;= 7 AND year_class_id &lt;= 9 AND right_num &gt;= 80 AND right_num &lt;= 89.5 THEN 2 ",
                "WHEN year_class_id &gt;= 7 AND year_class_id &lt;= 9 AND right_num &gt;= 90 AND right_num &lt;= 99.5 THEN 3 ",
                "WHEN year_class_id &gt;= 7 AND year_class_id &lt;= 9 AND right_num &gt;= 100 AND right_num &lt;= 109.5 THEN 4 ",
                "WHEN year_class_id &gt;= 7 AND year_class_id &lt;= 9 AND right_num &gt;= 110 THEN 5 ",
                "ELSE 0 ",
                "END AS integral ",
                "FROM plan_tb",

                "UNION ALL",

                // 数学通关率
                "SELECT",
                "*,",
                "2 AS mold_type,",
                "CASE WHEN right_num + amend_num &gt;= lowest_shutnum THEN '100%' ELSE '0%' END AS rate,",
                "CASE ",
                "WHEN year_class_id &gt;= 3 AND year_class_id &lt;= 6 AND (right_num + amend_num &gt;= lowest_shutnum) THEN 1",
                "WHEN year_class_id &gt;= 7 AND year_class_id &lt;= 9 AND (right_num + amend_num &gt;= lowest_shutnum) THEN 1",
                "ELSE 0",
                "END AS integral ",
                "FROM plan_tb ",

                "UNION ALL",

                // 费曼学习积分
                "SELECT",
                "*,",
                "3 AS mold_type,",
                "cha_integral AS rate,",
                "cha_integral AS integral ",
                "FROM plan_tb",
            ") AS tt ",
            "WHERE 1=1",
            "<when test='moldType!=null and moldType!=&apos;&apos; and moldType!=0'>",
                "AND tt.mold_type IN (${moldType}) ",
            "</when>",
            ") AS t ON t.teacher_id = t1.teacher_id ",
            "AND ( find_in_set( t.year_class_id, t1.year_class_id_str ) OR t1.year_class_id_str = '' ) ",
            "AND ( find_in_set( t.school_id, t1.school_id_str ) OR t1.school_id_str = '' ) ",
            "GROUP BY team_id ",
            "<when test='listState == 1'>",
                ",grade_id,mold_type,lesson_num ",
            "</when>",
            "<when test='listState == 2'>",
                ",grade_id ",
            "</when>",
            "<when test='listState == 3'>",
                ",grade_id,lesson_num ",
            "</when>",
            "<when test='teamId!=null and teamId!=&apos;&apos; '>",
                ",teacher_id",
                "HAVING teacher_id IS NOT NULL",
            "</when>",
            "ORDER BY grade_id,lesson_num,mold_type ASC;",
            "</script>"})
    public List<ChaPlan> getPassRadeIntegralTeamList(
            @Param("yearPart") String yearPart,
            @Param("quarterNum") String quarterNum,
            @Param("schoolId") String schoolId,
            @Param("teacherId") String teacherId,
            @Param("yearClassId") String yearClassId,
            @Param("subjectsId") Long subjectsId,
            @Param("classTypeId") String classTypeId,
            @Param("readingType") String readingType,
            @Param("courseVersionId") Long courseVersionId,
            @Param("isBeforQuarter") String isBeforQuarter,
            @Param("include") String include,
            @Param("taskCategoryId") String taskCategoryId,
            @Param("classify") String classify,
            @Param("trackType") String trackType,
            @Param("teamId") String teamId,
            @Param("lessonNumStart") String lessonNumStart,
            @Param("lessonNumEnd") String lessonNumEnd,
            @Param("startDate") String startDate,
            @Param("endDate") String endDate,
            @Param("type") String type,
            @Param("inType") String inType,// 1、全部，2已录
            @Param("listState") String listState,
            @Param("moldType") String moldType  // 1、正确率，2、通关率，3、费曼学习积分
    );

    /**
     * 数学积分战队详情
     */
    @Select({"<script>",
            "SELECT * ",
            "<when test='listState == 0'>",
                ",CASE WHEN DATE ( created_at ) BETWEEN '${startDate}' AND '${endDate}' THEN integral WHEN DATE ( integral_add_date_time ) BETWEEN '${startDate}' AND '${endDate}' THEN integral ELSE 0 END AS integral_all_date ",
            "</when>",

            "<when test='listState == 1 || listState == 2 '>",
                ",GROUP_CONCAT( DISTINCT lesson_num ) AS lessonNumNot,",
                "SUM(integral) AS integral_all,",
                "SUM( CASE WHEN DATE ( created_at ) BETWEEN '${startDate}' AND '${endDate}' THEN integral WHEN DATE ( integral_add_date_time ) BETWEEN '${startDate}' AND '${endDate}' THEN integral ELSE 0 END ) AS integral_all_date ",
            "</when>",

            "FROM ( ",
                "SELECT t.*,team_name,team_id,team_pid ",
                "FROM ( ",
                    "SELECT ",
                    "td.*, ",
                    "td.sourse_id AS teacher_id,",
                    "tm.team_name,",
                    "tm.id AS team_id,",
                    "tm.pid AS team_pid ",
                    "FROM",
                    "xmy_erp_db.track_market AS tm",
                    "LEFT JOIN xmy_erp_db.track_detail AS td ON tm.id = td.track_id AND tm.deleted = td.deleted ",
                    "WHERE ",
                    "tm.classify = ${classify} ",
                    "AND tm.track_type = ${trackType} ",
                    "AND tm.`status` = 1 ",
                    "AND tm.deleted = 0 ",
                    "AND tm.year_part = ${yearPart} ",
                    "AND tm.quarter_num = ${quarterNum} ",
                    "<when test='teamId!=null and teamId!=&apos;&apos; '>",
                        "AND tm.id in(${teamId})",
                    "</when>",
                    "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
                        "AND td.sourse_id = ${teacherId}",
                    "</when>",
                    "GROUP BY tm.id,td.sourse_id ",
                ") AS t1 ",
                "LEFT JOIN ( ",
                    "WITH plan_tb AS (",
                    "SELECT",
                    "t01.id,",
                    "t01.subjects_id,",
                    "t01.school_id,",
                    "t01.year_part,",
                    "t01.quarter_num,",
                    "t02.course_version_id,",
                    "t01.grade_id,",
                    "t01.teacher_id,",
                    "t01.teacher_name,",
                    "t01.student_name,",
                    "t01.grade_name,",
                    "t01.class_type_id,",
                    "t01.year_class_id,",
                    "t01.student_id,",
                    "t01.linkman_phone,",
                    "t02.task_course_num AS lesson_num,",
                    "( CASE WHEN t03.right_num IS NOT NULL AND t03.pass_rade &gt; 0",
                    "AND ( t03.right_num + t03.amend_num ) &gt;= t03.lowest_shutnum ",
                    "AND ( t03.right_num / t03.lowest_shutnum )* 100 &gt;= t03.pass_rade",
                    "THEN t03.lowest_shutnum ELSE t02.lowest_shutnum END ) AS lowest_shutnum,",
                    "IFNULL( t03.right_num, 0 ) AS right_num,",
                    "IFNULL( t03.amend_num, 0 ) AS amend_num,",
                    "t03.created_at, ",
                    "IFNULL( t03.integral, 0 ) AS cha_integral,",
                    "t03.integral_add_date_time ",
                    "FROM",
                    "(",
                        "SELECT",
                        "t1.*,",
                        "t1.class_type_id_new AS class_type_id,",
                        "t2.teacher_id,",
                        "t5.linkman_phone,",
                        "t5.`name` AS student_name,",
                        "t6.`name` AS teacher_name,",
                        "t2.`name` AS grade_name",
                        "FROM",
                        "xmy_erp_db.student_grade AS t1",
                        "INNER JOIN xmy_erp_db.grade AS t2 ON t1.grade_id = t2.id ",
                        "INNER JOIN per_student_account AS t3 ON t1.student_id = t3.student_id",
                        "INNER JOIN xmy_erp_db.student AS t5 ON t1.student_id = t5.id ",
                        "LEFT JOIN xmy_erp_db.rade_exclude_student AS t4 ON t4.classify_id = 0 AND t4.deleted = 0 AND t4.type = 2 AND t1.student_id = t4.student_id AND t1.year_part = t4.year_part AND t1.quarter_num = t4.quarter_num AND ( FIND_IN_SET( t1.subjects_id, t4.subjects_ids ) OR t4.subjects_ids IS NULL ) AND ( FIND_IN_SET( t1.school_id, t4.school_ids ) OR t4.school_ids IS NULL ) ",
                        "LEFT JOIN xmy_erp_db.staff AS t6 ON t2.teacher_id = t6.id ",
                        "WHERE",
                        "t1.year_part = ${yearPart} ",
                        "AND t1.quarter_num = ${quarterNum}",
                        "AND t1.lesson_type = 1",
                        "AND t1.deleted = 0 ",
                        "AND t1.subjects_id = ${subjectsId} ",
                        "AND t1.is_last = 1 ",
                        "AND t4.id is null ",
                        "AND t1.STATUS &lt;&gt; 3 ",
                        "AND t1.deleted = 0 ",
                        "<when test='include!=null and include!=&apos;&apos;'>",
                            "<when test='include == 0'>",
                                "AND t4.id is null ",
                            "</when>",
                            "<when test='include == 1'>",
                                "AND t4.id is not null ",
                            "</when>",
                        "</when>",
                        "<when test='isBeforQuarter == 0 and readingType == 1'>",
                            "AND t1.reading_status IN (1,5) ",
                        "</when>",
                        "<when test='isBeforQuarter == 1 and readingType == 1'>",
                            "AND t1.reading_status IN (1,5)",
                        "</when>",
                        "<when test='readingType == 2'>",
                            "AND ((t1.reading_status IN (1,5)) or (t1.reading_status in(3,4) and use_course_count > 0)) ",
                        "</when>",
                        "<when test='schoolId!=null and schoolId!=&apos;&apos;'>",
                            "AND t1.school_id IN(${schoolId})",
                        "</when>",
                        "<when test='yearClassId!=null and yearClassId!=&apos;&apos; '>",
                            "AND t2.year_class_id IN(${yearClassId})",
                        "</when>",
                        "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
                            "AND t1.class_type_id_new IN (${classTypeId})",
                        "</when>",
                        "<when test='teacherId!=null and teacherId!=&apos;&apos; and type != 4'>",
                            "AND t2.teacher_id = ${teacherId}",
                        "</when>",
                        "<when test='studentId!=null and studentId!=&apos;&apos;'>",
                            "AND t1.student_id = ${studentId}",
                        "</when>",
                        "GROUP BY",
                        "student_id ",
                    ") AS t01",
                    "INNER JOIN ( SELECT * FROM edu_task WHERE deleted = 0 and task_category_id = ${taskCategoryId} and subjects_id = ${subjectsId} and task_course_num BETWEEN ${lessonNumStart} and ${lessonNumEnd}) AS t02 ON t01.year_part = t02.year_part ",
                    "AND t01.quarter_num = t02.quarter_num ",
                    "AND t01.subjects_id = t02.subjects_id ",
                    "AND t01.class_type_id = t02.class_type_id",
                    "AND t01.year_class_id = t02.year_class_id",
                    "<when test= 'inType == 2'>",
                    "INNER",
                    "</when>",
                    "<when test= 'inType != 2'>",
                    "LEFT",
                    "</when>",
                    "JOIN (",
                        "SELECT ",
                        "student_id,",
                        "add_date,",
                        "lesson_num_finish,",
                        "year_class_id,",
                        "course_version_id,",
                        "class_type_id,",
                        "year_part,",
                        "quarter_num,",
                        "IFNULL( lesson_num, 0 ) AS lesson_num,",
                        "right_num,",
                        "is_last,",
                        "is_first,",
                        "amend_num, ",
                        "lowest_shutnum, ",
                        "brush_count, ",
                        "pass_rade,",
                        "pass_date_time, ",
                        "created_at,",
                        "IFNULL( integral, 0 ) AS integral,",
                        "integral_add_date_time ",
                        "FROM",
                        "cha_plan ",
                        "WHERE",
                        "year_part = ${yearPart} ",
                        "AND quarter_num = ${quarterNum}",
                        "AND task_category_id = ${taskCategoryId}",
                        "and deleted = 0",
                    ") AS t03 ON t01.year_part = t03.year_part ",
                    "AND t01.quarter_num = t03.quarter_num ",
                    "AND t01.student_id = t03.student_id ",
                    "AND t02.year_class_id = t03.year_class_id ",
                    "AND t02.class_type_id = t03.class_type_id ",
                    "AND t02.course_version_id = t03.course_version_id",
                    "<when test='courseVersionId!=null and courseVersionId!=&apos;&apos;'>",
                        "AND t02.course_version_id = ${courseVersionId}",
                    "</when>",
                    "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
                        "AND t01.subjects_id = ${subjectsId}",
                    "</when>",
                    "AND t02.task_course_num = t03.lesson_num",
                    "AND t03.is_first = 1 ",
                    ")",

                    // 数学正确率
                    "SELECT",
                    "*,",
                    "1 AS mold_type,",
                    "CASE WHEN lowest_shutnum &gt; 0 THEN CONCAT(ROUND(IFNULL(right_num / lowest_shutnum, 0) * 100, 2), '%') ELSE '0%' END AS rate,",
                    "CASE ",
                    // 小学
                    "WHEN year_class_id &gt;= 3 AND year_class_id &lt;= 6 AND right_num &gt;= 60 AND right_num &lt;= 69.5 THEN 1 ",
                    "WHEN year_class_id &gt;= 3 AND year_class_id &lt;= 6 AND right_num &gt;= 70 AND right_num &lt;= 79.5 THEN 2 ",
                    "WHEN year_class_id &gt;= 3 AND year_class_id &lt;= 6 AND right_num &gt;= 80 AND right_num &lt;= 89.5 THEN 3 ",
                    "WHEN year_class_id &gt;= 3 AND year_class_id &lt;= 6 AND right_num &gt;= 90 AND right_num &lt;= 99.5 THEN 4 ",
                    "WHEN year_class_id &gt;= 3 AND year_class_id &lt;= 6 AND right_num &gt;= 100 THEN 5 ",
                    // 初中
                    "WHEN year_class_id &gt;= 7 AND year_class_id &lt;= 9 AND right_num &gt;= 70 AND right_num &lt;= 79.5 THEN 1 ",
                    "WHEN year_class_id &gt;= 7 AND year_class_id &lt;= 9 AND right_num &gt;= 80 AND right_num &lt;= 89.5 THEN 2 ",
                    "WHEN year_class_id &gt;= 7 AND year_class_id &lt;= 9 AND right_num &gt;= 90 AND right_num &lt;= 99.5 THEN 3 ",
                    "WHEN year_class_id &gt;= 7 AND year_class_id &lt;= 9 AND right_num &gt;= 100 AND right_num &lt;= 109.5 THEN 4 ",
                    "WHEN year_class_id &gt;= 7 AND year_class_id &lt;= 9 AND right_num &gt;= 110 THEN 5 ",
                    "ELSE 0 ",
                    "END AS integral ",
                    "FROM plan_tb",

                    "UNION ALL",

                    // 数学通关率
                    "SELECT",
                    "*,",
                    "2 AS mold_type,",
                    "CASE WHEN right_num + amend_num &gt;= lowest_shutnum THEN '100%' ELSE '0%' END AS rate,",
                    "CASE ",
                    "WHEN year_class_id &gt;= 3 AND year_class_id &lt;= 6 AND (right_num + amend_num &gt;= lowest_shutnum) THEN 1",
                    "WHEN year_class_id &gt;= 7 AND year_class_id &lt;= 9 AND (right_num + amend_num &gt;= lowest_shutnum) THEN 1",
                    "ELSE 0",
                    "END AS integral ",
                    "FROM plan_tb ",

                    "UNION ALL",

                    // 费曼学习积分
                    "SELECT",
                    "*,",
                    "3 AS mold_type,",
                    "cha_integral AS rate,",
                    "cha_integral AS integral ",
                    "FROM plan_tb",
                ") AS t ON t.teacher_id = t1.teacher_id ",
                "AND ( find_in_set( t.year_class_id, t1.year_class_id_str ) OR t1.year_class_id_str = '' ) ",
                "AND ( find_in_set( t.school_id, t1.school_id_str ) OR t1.school_id_str = '' ) ",
                "WHERE 1=1",
                "<when test='moldType!=null and moldType!=&apos;&apos; and moldType!=0'>",
                    "AND tt.mold_type IN (${moldType}) ",
                "</when>",
                "<when test='startDate!=null and startDate!=&apos;&apos; and endDate!=null and endDate!=&apos;&apos; '>",
//                    "AND (( DATE(created_at) BETWEEN '${startDate}' AND '${endDate}' ) OR ( DATE(integral_add_date_time) BETWEEN '${startDate}' AND '${endDate}' ))",
                "</when>",

                "ORDER BY student_id,lesson_num,mold_type ASC ",
            ") AS tt ",
            "<when test='listState == 1'>",
                "GROUP BY student_id ",
            "</when>",
            "<when test='listState == 2'>",
                "GROUP BY student_id,lesson_num ",
            "</when>",
            "</script>"})
    public IPage<ChaPlan> getPassRadeIntegralTeamDetail(IPage<?> page,
                                                        @Param("yearPart") String yearPart,
                                                        @Param("quarterNum") String quarterNum,
                                                        @Param("schoolId") String schoolId,
                                                        @Param("teacherId") String teacherId,
                                                        @Param("studentId") String studentId,
                                                        @Param("yearClassId") String yearClassId,
                                                        @Param("subjectsId") Long subjectsId,
                                                        @Param("gradeId") String gradeId,
                                                        @Param("classTypeId") String classTypeId,
                                                        @Param("readingType") String readingType,
                                                        @Param("courseVersionId") Long courseVersionId,
                                                        @Param("isBeforQuarter") String isBeforQuarter,
                                                        @Param("studentName") String studentName,
                                                        @Param("include") String include,
                                                        @Param("taskCategoryId") String taskCategoryId,
                                                        @Param("classify") String classify,
                                                        @Param("trackType") String trackType,
                                                        @Param("teamId") String teamId,
                                                        @Param("lessonNumStart") String lessonNumStart,
                                                        @Param("lessonNumEnd") String lessonNumEnd,
                                                        @Param("startDate") String startDate,
                                                        @Param("endDate") String endDate,
                                                        @Param("type") String type,
                                                        @Param("inType") String inType,// 1、全部，2已录
                                                        @Param("moldType") String moldType,  // 1、正确率，2、通关率，3、费曼学习积分
                                                        @Param("listState") String listState
    );

    /**
     * 数学积分录入列表
     */
    @Select({"<script>",
            "SELECT",
            "t3.id,",
            "t3.integral,",
            "t1.year_part,",
            "t1.quarter_num,",
            "t1.subjects_id,",
            "t1.task_category_id,",
            "t1.course_version_id,",
            "t1.not_brush,",
            "t1.pass_rade AS task_pass_rade,",
            "t2.school_id,",
            "t2.grade_id,",
            "t4.teacher_id,",
            "t2.class_type_id_new AS class_type_id,",
            "t4.year_class_id,",
            "t2.student_id,",
            "t5.`name` AS student_name,",
            "(CASE WHEN t3.right_num is not null AND t3.pass_rade &gt;0 and (right_num + amend_num ) &gt;= t3.lowest_shutnum AND ( t3.right_num / t3.lowest_shutnum )* 100 &gt;= t3.pass_rade THEN t3.lowest_shutnum ELSE t1.lowest_shutnum END) as lowest_shutnum,",
            "t1.task_course_num AS lesson_num,",
            "t1.task_course_num,",
            "t3.right_num,",
            "t3.amend_num,",
            "t3.pass_rade,",
            "t3.brush_count ",
            "FROM",
            "edu_task AS t1",
            "INNER JOIN xmy_erp_db.student_grade AS t2 ON t1.year_part = t2.year_part ",
            "AND t1.quarter_num = t2.quarter_num ",
            "AND t1.deleted = t2.deleted ",
            "AND t1.year_class_id = t2.year_class_id ",
            "AND t1.class_type_id = t2.class_type_id_new ",
            "AND t1.course_version_id = ${courseVersionId}",
            "and t1.subjects_id = ${subjectsId}",
            "INNER JOIN xmy_erp_db.grade AS t4 ON t2.grade_id = t4.id",
            "INNER JOIN xmy_erp_db.student AS t5 ON t2.student_id = t5.id",
            "LEFT JOIN cha_plan AS t3 ON t1.year_part = t3.year_part ",
            "AND t1.quarter_num = t3.quarter_num ",
            "AND t2.student_id = t3.student_id ",
            "AND t1.class_type_id = t3.class_type_id ",
            "AND t1.task_category_id = t3.task_category_id ",
            "AND t1.task_course_num = t3.lesson_num ",
            "and t3.deleted = 0",
            "WHERE",
            "t1.year_part = ${yearPart}",
            "AND t1.quarter_num = ${quarterNum} ",
            "AND t1.task_category_id = ${taskCategoryId} ",
            "AND t1.deleted = 0 ",
            "AND t2.subjects_id = ${subjectsId} ",
            "AND t2.lesson_type = 1 ",
            "AND t2.reading_status IN ( 1, 5 ) ",
            "AND t2.`status` &lt;&gt; 3 ",
            "AND t2.is_last = 1 ",
            //先注释
//            "AND t3.integral = 0 ",
            "AND t3.is_first = 1 ",
//            "<when test='brushCount!=null and brushCount!=&apos;&apos; '>",
//                "AND t5.brush_count = ${brushCount} ",
//            "</when>",
            "<when test='lessonNum!=null and lessonNum!=&apos;&apos; '>",
                "<when test='isHistory==0'>",
                    "AND t1.task_course_num = ${lessonNum} ",
                "</when>",
                "<when test='isHistory==1'>",
                    "AND t1.task_course_num &lt;= ${lessonNum} ",
                "</when>",
            "</when>",
            "<when test='studentName!=null and studentName!=&apos;&apos; '>",
                "AND t5.name like '%${studentName}%' ",
            "</when>",
            "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
                "AND t2.school_id in(${schoolId}) ",
            "</when>",
            "<when test='yearClassId!=null and yearClassId!=&apos;&apos; '>",
                "AND t4.year_class_id in(${yearClassId}) ",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
                "AND t4.teacher_id = ${teacherId} ",
            "</when>",
            "<when test='gradeId!=null and gradeId!=&apos;&apos; '>",
                "AND t2.grade_id = ${gradeId} ",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
                "AND t4.course_type_id = ${classTypeId} ",
            "</when>",
            "ORDER BY lesson_num,student_id ASC",
            "</script>"})
    public IPage<ChaPlan> getChaPanIntegralAddList(IPage<?> page,
                                                   @Param("yearPart") String yearPart,
                                                   @Param("quarterNum") String quarterNum,
                                                   @Param("schoolId") String schoolId,
                                                   @Param("teacherId") String teacherId,
                                                   @Param("gradeId") String gradeId,
                                                   @Param("yearClassId") String yearClassId,
                                                   @Param("classTypeId") String classTypeId,
                                                   @Param("lessonNum") String lessonNum,
                                                   @Param("isHistory") Integer isHistory,
                                                   @Param("studentName") String studentName,
                                                   @Param("subjectsId") Long subjectsId,
                                                   @Param("courseVersionId") Long courseVersionId,
                                                   @Param("brushCount") String brushCount,
                                                   @Param("taskCategoryId") Integer taskCategoryId);


}
